这里是一个纯的XPath 1.0溶液:
使用:
concat('{',
substring-before(
substring-after(
substring-after(., 'my.function('),
'{'
),
');'
)
)
XSLT - 基于验证:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>
<xsl:template match="/">
<xsl:copy-of select=
"concat('{',
substring-before(
substring-after(
substring-after(., 'my.function('),
'{'
),
');'
)
)
"/>
</xsl:template>
</xsl:stylesheet>
当该变换被应用上所提供的XML文档:
<script type="text/javascript">
my.function("bar", {"foo1": false, "foo2": true, "foo3": "foobar!"});
</script>
XPath表达式(以上)进行评估,其结果是输出:
{"foo1": false, "foo2": true, "foo3": "foobar!"}
正是我需要的,谢谢! – David 2011-12-26 04:12:53