xsl-list
[Top] [All Lists]

Re: [text nodes] Unmatching text nodes wrongly inserted

2004-09-24 01:33:53
Hi Stefano,

The stylesheet you posted:

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

does not contain a <xsl:template match="/"> (matching the document root node).
In such case, the default templates are applied. If you add a match="/" 
template,
you can just select the elements you need, and no default templates will be 
called:

<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="/">
        <xsl:apply-templates select="//xdm:fields"/>
    </xsl:template>
    <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">
        <label x="20" y="56" width="12">
            <xsl:value-of select="."/>
        </label>
    </xsl:template>
</xsl:stylesheet>

In real situations it might be better not to use "//xdm:fields", but pass a 
full path like
"/xdm:documents/xdm:document/xdm:body/xdm:pages/xdm:page/xdm:fields"
because "//" always scans the complete input document. Or even better, use a 
key:

    <xsl:key name="fields" match="xdm:field" use="@name"/>
    <xsl:template match="/">
        <xsl:apply-templates select="key('fields', 'CSBFT242')"/>
    </xsl:template>

Salute!
Anton