由XSLT显示

时间:2019-06-20 07:03:07

标签: xslt

我想要print属性并为其添加一些值。

输入:

<figure id="fig_1">
 <dis>text</dis>
</figure>

我的输出:

<image ref="fig_1"
        comment="text the&#xA;                                    "/>

尝试代码:

<xsl:template match="dis[parent::figure]">
    <xsl:variable name="fig_name" select="parent::fig/@id"/>
    <image ref="{$fig_name}">
        <xsl:attribute name="comment">
            <xsl:value-of select="text()"/>
        </xsl:attribute>
    </tps:image>
</xsl:template>

我要删除所有&#xA;。我该怎么办。

1 个答案:

答案 0 :(得分:1)

使用normalize-space()函数删除不必要的空白。

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output omit-xml-declaration="yes" method="xml" version="1.0" />        
    <xsl:template match="long-desc[parent::fig]">
        <xsl:variable name="fig_name" select="parent::fig/@id"/>
        <image ref="{$fig_name}">
            <xsl:attribute name="comment">
                <xsl:value-of select="normalize-space(text())"/>
            </xsl:attribute>
        </image>
    </xsl:template>
</xsl:stylesheet>
相关问题