This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: Confusion with template!
- To: xsl-list at lists dot mulberrytech dot com
- Subject: Re: [xsl] Confusion with template!
- From: Mike Brown <mike at skew dot org>
- Date: Fri, 21 Sep 2001 16:57:15 -0600 (MDT)
- Reply-To: xsl-list at lists dot mulberrytech dot com
Sumev wrote:
> Hi,
>
> XSLT -->
>
> <?xml version="1.0" encoding="UTF-8"?>
> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> version="1.0">
> <xsl:template match="/">
> <xsl:element name="ADDRESS">
> <xsl:apply-templates/>
> </xsl:element>
> </xsl:template>
Remember:
apply-templates = "go process these nodes" (all children by default);
template match = "how to process one of these nodes".
Based on your input and desired output, I'd say you want, simply, this:
<xsl:template match="/">
<xsl:apply-templates select="ADDRESS/RECORD"/>
</xsl:template>
<xsl:template match="RECORD">
<RECORD ID="{@ID}">
<PALMRECID>
<xsl:value-of select="EXCHNGRECID"/>
</PALMRECID>
<CATEGORYINDEX>
<xsl:value-of select="CATEGORY"/>
</CATEGORYINDEX>
<NAME>
<xsl:value-of select="LASTNAME"/>
</NAME>
<FIRSTNAME>
<xsl:value-of select="FIRSTNAME1"/>
</FIRSTNAME>
</RECORD>
</xsl:template>
You want to process each RECORD element. Your stylesheets were not
doing that.. you were stopping at the ADDRESS element and trying
to obtain data by reaching down further into the tree from there.
Also:
value-of = "create a text node", and if the select identifies a
node-set, the text node is created using only the first node in
the set.
You don't need to use "//" anywhere. This is usually indicative of
desperation :)
- Mike
____________________________________________________________________________
mike j. brown, fourthought.com | xml/xslt: http://skew.org/xml/
denver/boulder, colorado, usa | personal: http://hyperreal.org/~mike/
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list