Xml XSLT:包装文本而不转换为字符串
通过将子元素转换为字符串,有没有一种方法可以在不丢失子元素的情况下包装节点的特定部分 这就是我得到的:Xml XSLT:包装文本而不转换为字符串,xml,xslt,xml-parsing,xslt-2.0,Xml,Xslt,Xml Parsing,Xslt 2.0,通过将子元素转换为字符串,有没有一种方法可以在不丢失子元素的情况下包装节点的特定部分 这就是我得到的: <root> <caption>Figure 3.1 Description of an Image, sometimes with <inline>Bold</inline> or <inline>Italic</inline> emphases.</caption> </root>
<root>
<caption>Figure 3.1 Description of an Image, sometimes with <inline>Bold</inline> or <inline>Italic</inline> emphases.</caption>
</root>
图形 3.1 图像描述,有时用粗体或斜体强调。
。。。这就是我需要的:
<root>
<caption><inline>Figure 3.1</inline>Description of an Image, sometimes with <inline>Bold</inline> or <inline>Italic</inline> emphases.</caption>
</root>
图形 3.1图像描述,有时用粗体或斜体强调。
我考虑使用正则表达式^Figure\s[0-9]+.[0-9]+
捕捉不同的变化(如图11.10),并尝试了数小时来解决问题,但如果不删除以下
的话,就无法做到这一点。。。有可能吗
我正在使用XSLT2.0
谢谢大家! 为文本节点编写模板
<xsl:template match="caption/text()">
<xsl:analyze-string select="." regex="^Figure\s[0-9]+\.[0-9]+">
<xsl:matching-substring>
<inline><xsl:value-of select="."/></inline>
</xsl:matching-substring>
<xsl:non-matching-substring>
<xsl:value-of select="."/>
</xsl:non-matching-substring>
</xsl:analyze-string>
</xsl:template>
当然,您可以使用标识转换模板启动样式表:
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
谢谢!很好用!我以前也尝试过同样的解决方案,但由于“Figure”和数字之间有一个小空格( ;)而失败了。。。