This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: Design question
- From: Jeni Tennison <jeni at jenitennison dot com>
- To: Antonio Fiol <fiol at w3ping dot com>
- Cc: xsl-list at lists dot mulberrytech dot com
- Date: Wed, 10 Jul 2002 09:46:42 +0100
- Subject: Re: [xsl] Design question
- Organization: Jeni Tennison Consulting Ltd
- References: <5.1.0.14.0.20020709170838.00a53340@digexch1><3D2BE712.3080906@w3ping.com>
- Reply-to: xsl-list at lists dot mulberrytech dot com
Hi Antonio,
> You could do what you say, but why not doing the following:
>
> <xsl:template match="test[@type='positive']">
> <da:Positive name="@name">
> <xsl:for-each select="param">
> <xsl:choose>
> <xsl:when test="starts-with(@name,'p')">
> <xsl:attribute name="{@name}"><xsl:value-of
> select="."/></xsl:attribute>
> </xsl:when>
> <xsl:otherwise>
> <xsl:element name="da:Date">
> <xsl:attribute name="number"><xsl:value-of
> select="substring(@name,4)"/></xsl:attribute>
> <xsl:attribute name="value"><xsl:value-of
> select="."/></xsl:attribute>
> </xsl:element>
> </xsl:otherwise>
> </xsl:choose>
> </xsl:for-each>
> </da:Positive>
> </xsl:template>
The reason Jay couldn't use that is that for some arrangements of
parameters this would lead to attributes being added after child
elements have already been added to the da:Positive element, which is
an error in XSLT. For example, with the input specified:
<test type="positive" name="Test 1">
<param name="p1">123</param>
<param name="date1">July 9</param>
<param name="p2">false</param>
</test>
Your code is equivalent to:
<da:Positive name="@name"> <!-- [sic -- forgot {}s] -->
<xsl:attribute name="p1">123</xsl:attribute>
<xsl:element name="da:Date">
<xsl:attribute name="number">1</xsl:attribute>
</xsl:element>
<xsl:attribute name="p2">false</xsl:attribute>
</da:Positive>
Processors that don't halt when they encounter an attribute being
added after element content ignore the attribute, so either you get an
error or erroneous output; either way it's not much good.
Cheers,
Jeni
---
Jeni Tennison
http://www.jenitennison.com/
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list