Re: [xsl] How to strip off all <xsd:annotation> ...</xsd.annotation> tags

Subject: Re: [xsl] How to strip off all <xsd:annotation> ...</xsd.annotation> tags
From: "Ben Stover" <bxstover@xxxxxxxxxxx>
Date: Thu, 13 Aug 2009 17:31:11 +0200
Thank you Michael.

However I would like to keep the xml:space="preserve" instruction because it ensures that the output is on a minimum human readable format.
Without this I have one very, very long line. This is unacceptable for me.

Would it help perhaps to move the "xml:space="preserve" instruction to another place in the stylesheet?
Maybe something like this:

   <xsl:template match="@* | node()" xml:space="preserve">
        <xsl:apply-templates select="@* | node()"/>


   <xsl:template match="@* | node()">
        <xsl:apply-templates select="@* | node()"/ xml:space="preserve">

Sorry, I am not an expert in XSLT.


On Thu, 13 Aug 2009 16:52:17 +0200, Michael Ludwig wrote:

>Martin Honnen schrieb:
>> Ben Stover wrote:
>>> thank you for your suggestion. Unfortunately your script show the
>>> following error (when running with Saxon):

>>>   XTDE0410: An attribute node (targetNamespace) cannot be created
>>>   after the children of the containing element at xsl:apply-templates
>>>   (file:/D:/xslt/Saxon/strip%20annotation%20tags/stripannotationtags.xsl#11)
>>>      processing /xsd:schema/@targetNamespace
>>>   in built-in template rule

>>> Do you know what's wrong?
>> I can't explain that error. And I have now tried the stylesheet
>> against the schema and it processes
>> that without errors. Can you provide a minimal but complete XML input
>> document that causes that error?

>Ben, please keep things like this on list instead of sending mail
>privately. Your stylesheet is not the one Martin posted; you introduced
>a significant change:

><xsl:stylesheet xml:space="preserve"
>    xmlns:xsl="";
>    xmlns:xsd="";
>    version="2.0">

>    <xsl:template match="xsd:annotation"/>

>    <xsl:template match="@* | node()">
>      <xsl:copy>
>        <xsl:apply-templates select="@* | node()"/>
>      </xsl:copy>
>    </xsl:template>


>The xml:space on the xsl:stylesheet is a very bad idea. It leads to
>every single whitespace-only text node being relevant, which makes the
>stylesheet create whitespace-only text nodes after the <xsl:template>
>and after <xsl:copy> (and elsewhere). So child nodes are created
>*before* applying templates to attributes. Creating attributes after
>having created child nodes is not allowed.

>Just to illustrate the principle here, the following will work (but it's
>a very odd arrangement, avoid that):

>    <xsl:template match="@* | node()"><xsl:copy><xsl:apply-templates 
>select="@* | node()"/>
>      </xsl:copy>
>    </xsl:template>

>Just get rid of the xml:space="preserve" - it's the source of your
>problems. Sometimes you'll want whitespace-only text nodes in your
>source tree (XSLT stylesheet module) to be kept and copied, but then
>you'll probably also want to localize the effect of the xml:space you
>insert to achieve that effect.

>Michael Ludwig

Current Thread