xsl-list
[Top] [All Lists]

Re: [text nodes] Unmatching text nodes wrongly inserted

2004-09-24 00:44:27
OK, but there are many more elements outside the <fields> hierarchy, as you
can note in the posted xml example:

<?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>

I would like to avoid explicit template declarations for EACH unwanted
element (<documents>, <document>, <header>, <body>, <pages> and so on),
thinking about more complex scenarios.
If I applied the posted xsl transformation:

<?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 select="xdm:field[(_at_)name='CSBFT242']"/>
 </map>
</xsl:template>
<xsl:template match="xdm:field[(_at_)name='CSBFT242']">
 <label x="20" y="56" width="12">
  <xsl:value-of select="."/>
 </label>
</xsl:template>
</xsl:stylesheet>

to the above posted xml, it would result in an odd xml containing the
unwanted "Fattura 1924/2003 di AAAAAA SpA" value of the
/document/header/caption text node, due to the famous default template
(argggh! wouldn't it be better if the W3C XSLT workgroup had defined an
empty default template instead of the text-spitting one we have to deal
with?). I'm just looking for an ultimate solution that doesn't let me worry
about the "text-spitting" issue!

Furthermore: do you know why the matching xpath expression "node()" excludes
neatly all the other matching templates?

Thanks

Stefano

-----Messaggio originale-----
Da:   Anton Triest [SMTP:anton(_at_)cking(_dot_)be]
Inviato:      giovedì 23 settembre 2004 19.33
A:    xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Oggetto:      Re: [xsl] R: [xsl] [text nodes] Unmatching text nodes
wrongly inserted

<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?

<xsl:apply-templates/> selects all the children. If you only need 
one particular element, it's easier to select it in apply-templates:

<xsl:apply-templates select="xdm:field[(_at_)name='CSBFT242']"/>

and then the matching template will only be called for that element.

<xsl:template match="xdm:fields">
   <xsl:apply-templates select="xdm:field[(_at_)name='CSBFT242']"/>
</xsl:template>
<xsl:template match="xdm:field">
   ... process that one field ...
</xsl:template>

HTH,
Anton

--+------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--+--