XSLT Transformation Issue Disabling Output

I have an xml where I have saved some html in comments like this

 <root> 
   <node>
     <!-- 
            <a href="mailto:some@one.com"> Mail me </a>
      -->
</node>
</root>

      

now in my Transform Xslt code, I provide an XPathNavigator that points to the node, and in the xslt I pass the comment value as a parameter.

assuming $ href will be <a href="mailto:some@one.com"> Mail me </a>

in xslt i do <xsl:value-of select="$href" disable-output-escaping="yes">

but $ href still escapes, xslt transform result occurs with <>

Does anyone know what is wrong with it, any help in this regard would be much appreciated.

Thanks Regards Azim

+1


source to share


3 answers


When part of a comment node loses its special meaning - thus "href" is not a node, so you cannot use it to select stuff.

You can choose such comments:

<xsl:template match="/">
<xsl:value-of select="/root/node/comment()" disable-output-escaping="yes"/>
</xsl:template>

      



This will be generated based on your XML input:

cristi:tmp diciu$ xsltproc test.xsl test.xml 
<?xml version="1.0"?>

        <a href="mailto:some@one.com"> Mail me </a>

      

+2


source


As mentioned in diciu, after commenting out, the text inside is no longer parsed by XML.

One solution to this problem is to use a two-pass approach. One pass to remove commented <a href=""></a>

node and place it in the XML normal, and the second pass, to enrich the data desired output: <a href="">Your Text Here</a>

.

A second, one-pass approach would be to extract the text you want from a comment (in this case an email address) via a regular expression (or, in our case, just pull from XML), and then create the markup needed around it ...



<xsl:template match="ahrefmail/comment()">
    <xsl:element name="a">
        <xsl:attribute name="href" select="../../mail"/>
        <xsl:attribute name="class" select="'text'"/>
        <xsl:text>Mail Me!</xsl:text>
    </xsl:element>
</xsl:template>

      

This assumes that you already have an identity template .

+1


source


I tried what you just said didnt work with the xml I am using,

<?xml version="1.0" ?>
  <root>
    <institution id="1">
        <data>
        <ahrefmail>
            <!--
        <a href='mailto:ibank@abibbankuk.com' class='text'></a>
             -->
        </ahrefmail>

        <mail>
            ibank@abibbankuk.com
        </mail>
        </data>
    </institution>


    <institution id="2">
        <data>
        <ahrefmail>
            <!--
        <a href='mailto:ibank@abibbankuk2.com' class='text'></a>
        -->
        </ahrefmail>

        <mail>
            ibank@abibbankuk2.com
        </mail>
        </data>
    </institution>

</root>

      

in xslt i do

where $ id is passed as parameter == 1 ahrefmail node is still escaped with lt and gt

Thanks Regards Azim

-1


source







All Articles