XSLT如何处理散布在其他XML元素中的多个XML文本节点
当一个元素包含其他元素时,如何保持文本元素的顺序?在此(简化)示例中: 我试过:XSLT如何处理散布在其他XML元素中的多个XML文本节点,xslt,Xslt,当一个元素包含其他元素时,如何保持文本元素的顺序?在此(简化)示例中: 我试过: <xsl:template match="block"> <xsl:value-of select="."> <xsl:apply-templates select="bsub"/> <xsl:value-of select="."> </xsl:template> <xsl:template match="bs
<xsl:template match="block">
<xsl:value-of select=".">
<xsl:apply-templates select="bsub"/>
<xsl:value-of select=".">
</xsl:template>
<xsl:template match="bsub">
<xsl:value-of select=".">
</xsl:template>
如何使用
选择单个文本元素(属于
)?不要使用的值来处理这样的混合内容-改用应用模板,这一切都会对您有用。此XSLT 1.0样式表
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/">
<t>
<xsl:apply-templates />
</t>
</xsl:template>
<xsl:template match="block|bsub">
<xsl:apply-templates />
</xsl:template>
<xsl:template match="text()">
<xsl:value-of select="concat(.,' ')" />
</xsl:template>
</xsl:stylesheet>
…应用于输入文档时
<block>1st text<bsub>2nd text</bsub>3rd text</block>
1st text第2 text第3 text
…产生
<t>1st text 2nd text 3rd text </t>
1文本第2文本第3文本
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/">
<t>
<xsl:apply-templates />
</t>
</xsl:template>
<xsl:template match="block|bsub">
<xsl:apply-templates />
</xsl:template>
<xsl:template match="text()">
<xsl:value-of select="concat(.,' ')" />
</xsl:template>
</xsl:stylesheet>
<block>1st text<bsub>2nd text</bsub>3rd text</block>
<t>1st text 2nd text 3rd text </t>