[xsl] R: [xsl] [text nodes] Unmatching text nodes wrongly inserted

Subject: [xsl] R: [xsl] [text nodes] Unmatching text nodes wrongly inserted
From: Chizzolini Stefano <chist@xxxxxx>
Date: Thu, 23 Sep 2004 18:29:08 +0200
OK, that's fine:

> <xsl:template match="xdm:field"/> <!-- this is the empty template -->

But how can I extend this concept to exclude not just the unwanted <field>
elements, but ANY element OTHER THAN those I need to render?
For the purpose, I thought a declaration like the following:

<xsl:template match="node()"/>

that should (in my hope!) exclude any rendering for all the non-root
elements, at the same time (due to the template priority algorithm (XSLT 1.0
Specification, ' 5.5, http://www.w3.org/TR/xslt#conflict)) allowing the
correct render of the wanted elements:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
version="1.0" xmlns:xdm="http://www.aaa.it/consulta/xdmModel";>
<xsl:template match="node()"/> <!-- empty template for all the non-root
nodes -->
<xsl:template match="xdm:fields">
 <map font-family="Courier" font-size="10pt" height="1" x-unit="in/10"
y-unit="in/6">
  <xsl:apply-templates/>
 </map>
</xsl:template>
<xsl:template match="xdm:field[@name='CSBFT242']">
 <label x="20" y="56" width="12">
  <xsl:value-of select="."/>
 </label>
</xsl:template>
</xsl:stylesheet>

sadly, this syntax doesn't work at all: it seems to keep the highest
priority to the empty template, ignoring any else (the result is an empty
xml).

You know: I haven't grasped the intricacies of XSLT semantics yet!

Thanks for your help.

Stefano

> -----Messaggio originale-----
> Da:	Francesco Barresi [SMTP:kywocs@xxxxxxxxx]
> Inviato:	mercoledl 22 settembre 2004 18.28
> A:	xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Oggetto:	Re: [xsl] [text nodes] Unmatching text nodes wrongly
> inserted
>
> Hi Stefano,
>
> The 'extra' text inserted:
>
> 1
> 2003-12-18
>
> Is because you used <xsl:apply-templates/> in the "xdm:fields"
> template, so the processor process all his childs, this is:
>
> <field name="CSBFT242">FATTURA DI VENDITA</field>
> <field name="CSBFT009">1</field>
> <field name="CSBFT010">2003-12-18</field>
>
> For the first "xdm:field" there is no problem because you defined a
> template for that, but for the other 2 child you didn't defined any
> template, then the processor apply his default template, wich in most
> cases the built-in template is to output the text contained in an
> element.
>
> You could "delete"  the default template  simply defining an empty a
> template for the <xdm:field> elements, and the template matching
> "xdm:field[@name='CSBFT242']" will still work.
> Something like this:
>
> <?xml version="1.0" encoding="utf-8"?>
> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
> version="1.0" xmlns:xdm="http://www.aaa.it/consulta/xdmModel";>
> <xsl:template match="xdm:fields">
>  <map font-family="Courier" font-size="10pt" height="1" x-unit="in/10"
> y-unit="in/6">
>   <xsl:apply-templates/>
>  </map>
> </xsl:template>
> <xsl:template match="xdm:field"/> <!-- this is the empty template -->
> <xsl:template match="xdm:field[@name='CSBFT242']">
>  <label x="20" y="56" width="12">
>   <xsl:value-of select="."/>
>  </label>
> </xsl:template>
> </xsl:stylesheet>
>
> Bye.
> Francesco.
>
> PD:Scusa il mio inglese, fa abbastanza pena :)
>
> On Wed, 22 Sep 2004 18:15:16 +0200, Chizzolini Stefano <chist@xxxxxx>
> wrote:
> > Hi all,
> >
> > I tried to render this xml:
> >
> > <?xml version="1.0" encoding="ISO-8859-1"?>
> > <documents xmlns="http://www.aaa.it/consulta/xdmModel";>
> >  <document id="2003722011924">
> >   <header>
> >    <caption>Fattura 1924/2003 di AAAAAA SpA</caption>
> >   </header>
> >   <body format="pdf" base="fatture/">
> >    <pages>
> >     <page template="FTNORM.pdf">
> >      <fields>
> >       <field name="CSBFT242">FATTURA DI VENDITA</field>
> >       <field name="CSBFT009">1</field>
> >       <field name="CSBFT010">2003-12-18</field>
> >      </fields>
> >     </page>
> >    </pages>
> >   </body>
> >  </document>
> > </documents>
> >
> > transforming it with this ridiculous XSLT stylesheet:
> >
> > <?xml version="1.0" encoding="utf-8"?>
> > <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
> > version="1.0" xmlns:xdm="http://www.aaa.it/consulta/xdmModel";>
> >  <xsl:template match="xdm:fields">
> >   <map font-family="Courier" font-size="10pt" height="1" x-unit="in/10"
> > y-unit="in/6">
> >    <xsl:apply-templates/>
> >   </map>
> >  </xsl:template>
> >  <xsl:template match="xdm:field[@name='CSBFT242']">
> >   <label x="20" y="56" width="12">
> >    <xsl:value-of select="."/>
> >   </label>
> >  </xsl:template>
> > </xsl:stylesheet>
> >
> > but the result was quite horrific:
> >
> > <?xml version="1.0"?>
> > Fattura 1924/2003 di AAAAAA SpA
> > <map font-family="Courier" font-size="10pt" height="1" x-unit="in/10"
> > y-unit="in/6" xmlns:xdm="http://www.aaa.it/consulta/xdmModel";>
> >  <label x="20" y="56" width="12">FATTURA DI VENDITA</label>
> >  1
> >  2003-12-18
> > </map>
> >
> > As you can see, the core transformation is right, but the XSLT processor
> > inserted also all the unwanted text node values!
> > I checked all the above code, but I'm really puzzled.
> >
> > What's wrong in my stylesheet?
> >
> > Many thanks
> >
> > Stefano
> >
> >
>
>
>
> --
> www.GetFirefox.com !!

Current Thread