0

I want print attribute and put some values to it.

Input :

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

my output:

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

Tried code :

<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>

I want to remove all &#xA;. How can I do it.

Ed Bangga
  • 12,879
  • 4
  • 16
  • 30
user5000
  • 39
  • 6

1 Answers1

1

use normalize-space() function to remove unnecessary white 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>
Ed Bangga
  • 12,879
  • 4
  • 16
  • 30