[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: commenting an XML element [XSLT 1.0][xsltproc]

Subject: Re: commenting an XML element [XSLT 1.0][xsltproc]
From: Wolfgang Laun <wolfgang.laun@xxxxxxxxx>
Date: Wed, 18 Aug 2010 13:23:54 +0200
Re:  commenting an XML element [XSLT 1.0][xsltproc]
Shouldn't there be an fn:data() wrapping the '.' in <xsl:value-of
select="."/> for a text() node?
-W

On 18 August 2010 13:09, Martin Honnen <Martin.Honnen@xxxxxx> wrote:
>
> pankaj.c@xxxxxxxxxxxxxxxxxx wrote:
>>
>> Hello all,
>>
>> I am trying to comment one of the empty element (<spec/>) in my xml tree
but seems I am missing something.
>>
>>
>> My stylesheet look something below:
>>
>> <xsl:template match="spec">
>>        <xsl:comment>
>>           <xsl:apply-templates select="self::*" mode="comment"/>
>>     </xsl:comment>
>> </xsl:template>
>>
>>   <xsl:template match="*" mode="comment">
>>        <xsl:value-of select="'&lt;'"/>
>>            <xsl:value-of select="name()"/>
>>        <xsl:value-of select="'&gt;'"/>
>>            <xsl:apply-templates select="@*|node()" mode="comment" />
>>        <xsl:value-of select="'&lt;/'"/>
>>            <xsl:value-of select="name()"/>
>>        <xsl:value-of select="'&gt;'"/>
>>    </xsl:template>
>>
>>    <xsl:template match="text()" mode="comment">
>>        <xsl:value-of select="."/>
>>    </xsl:template>
>>
>>    <xsl:template match="@*" mode="comment">
>>        <xsl:value-of select="name()"/>
>>        <xsl:text>="</xsl:text>
>>        <xsl:value-of select="."/>
>>        <xsl:text>" </xsl:text>
>>    </xsl:template>
>>
>> This is what I get using xsltproc (MAC)
>>
>> Error:
>> element text
>> misplaced text element
>>
>> Any ideas please.
>>
>> PS: I do have my identity transform defined in stylesheet.
>
> I don't see any problem with that code, unless a spec element contains "--".
But in that case (XML input being
>
> <root>
>  <spec foo="bar"><baz/></spec>
>  <spec>--</spec>
> </root>
>
> stylesheet being
>
> <xsl:stylesheet
>  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>  version="1.0">
>
>  <xsl:template match="@* | node()">
>    <xsl:copy>
>      <xsl:apply-templates select="@* | node()"/>
>    </xsl:copy>
>  </xsl:template>
>
> <xsl:template match="spec">
>        <xsl:comment>
>           <xsl:apply-templates select="self::*" mode="comment"/>
>     </xsl:comment>
> </xsl:template>
>
>   <xsl:template match="*" mode="comment">
>        <xsl:value-of select="'&lt;'"/>
>            <xsl:value-of select="name()"/>
>        <xsl:value-of select="'&gt;'"/>
>            <xsl:apply-templates select="@*|node()" mode="comment" />
>        <xsl:value-of select="'&lt;/'"/>
>            <xsl:value-of select="name()"/>
>        <xsl:value-of select="'&gt;'"/>
>    </xsl:template>
>
>    <xsl:template match="text()" mode="comment">
>        <xsl:value-of select="."/>
>    </xsl:template>
>
>    <xsl:template match="@*" mode="comment">
>        <xsl:value-of select="name()"/>
>        <xsl:text>="</xsl:text>
>        <xsl:value-of select="."/>
>        <xsl:text>" </xsl:text>
>    </xsl:template>
>
> </xsl:stylesheet>
>
> ) xsltproc (on Windows) gives a clear error message:
>
> runtime error: file test2010081801Xsl.xml line 12 element comment
> xsl:comment : '--' or ending '-' not allowed in comment
>
> So try a different XSLT processor if you have a problem with xsltproc to see
whether another processor succeeds.
>
> If you still have problems then consider to post complete samples allowing
us to reproduce.
>
> --
>
>        Martin Honnen
>        http://msmvps.com/blogs/martin_honnen/

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.