Re: [xsl] Newbie question, commenting out an element

Subject: Re: [xsl] Newbie question, commenting out an element
From: "Douglas Wade" <douglaswade@xxxxxxxxx>
Date: Sun, 21 Dec 2008 10:39:50 -0800
Thank you ... I had thought of using perl. In fact the transformation
script is a perl script that first converts from SGML to XML and then
changes graphic names and bunch of other strings. The problem for me
with perl is that I have to do more work to handle items, like
elements starting on one line and finishing on another. I wanted to
move from my serial and string based approach to XSL thinkin' I could
get my skills more current and do more with less effort.

D


On Sat, Dec 20, 2008 at 11:05 PM, Deborah Pickett
<debbiep-list-xsl@xxxxxxxxxx> wrote:
> Hi Douglas,
>
> Douglas Wade wrote:
>> <applic><assert></assert></
>> applic>
>> to
>> <!-- <applic><assert></assert></applic> -->
>
> The reason this isn't working for you is that XSLT doesn't produce
> serialized XML (at least, not directly).  It produces a result tree
> (think of something like a DOM tree), which is serialized to XML by
> another agent*.  In other words, XSLT works on elements and nodes, not
> tags and text.
>
> It's not allowed for an XML result tree to have comment nodes (made with
> <xsl:comment>) with child nodes other than text.  If you try something like
>
> <xsl:comment><xsl:element name="foo"/></xsl:comment>
>
> you will get an error reminding you of this.
>
> That said, there are a couple of ways you can do this.  One is to not
> use XSLT at all, and treat this as a text-substitution problem to be
> done in a general text-processing language like Perl.  The other is to
> use an XPath extension function such as saxon:serialize(), which can
> turn an XML result tree into a string that represents the tree, which
> you can then stick into your output with <xsl:value-of>.
>
> Whichever way you go, you will need to ensure that the comment never
> contains the sequence of characters "--", which is forbidden in XML
> comments to prevent the possibility of comments nesting.
>
> * That agent is usually your XSLT processor, after it has finished
> processing the stylesheet, but XSLT processors don't have to do this.

Current Thread