This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: Stuck on Name() and variable
- From: Joerg Heinicke <joerg dot heinicke at gmx dot de>
- To: xsl-list at lists dot mulberrytech dot com
- Date: Tue, 06 Aug 2002 02:26:44 +0200
- Subject: Re: [xsl] Stuck on Name() and variable
- References: <030c01c23cc0$0292fcd0$ca10a8c0@houston.apbfn.com>
- Reply-to: xsl-list at lists dot mulberrytech dot com
After a quick look on your code, I would suggest, that the error is in
this line:
<xsl:value-of select="MapMD/attribute::*[name() = $AttrName]" />
The context node is (from the for-each) an attribute of //Map[@schema],
so you are searching for //Map[@schema]/attribute::*[position() >
2]/MapMD/attribute::*[name() = $AttrName]. But an attribute can never
have an element as child node.
Maybe in front of the for-each you have to store MapMD in a variable:
(I don't know what's the current context.)
<xsl:variable name="MapMD" select="MapMD"/>
and refer to it in the for-each:
<xsl:value-of select="$MapMD/attribute::*[name() = $AttrName]" />
Some more comments on your code (even it would be interesting to know
the context of this code):
<xsl:attribute name="data">
<xsl:variable name="Market" select="node()"/>
Are you sure you want to store all child nodes of the current context
node in this variable?
<xsl:variable name="Key" select="parent::node()"/>
If you can answer the last question with 'yes', then you can shorten
this code to <xsl:variable name="Key" select="."/>
<xsl:for-each select="//Map[@schema]/attribute::*[position() > 2]" >
I think it's very dangerous to rely on position() when using on
attribute::*. There is no order of attributes, maybe you should exclude
some attributes by their name and not their position:
<xsl:for-each select="//Map[@schema]/attribute::*[name() != 'col0']">
Furthermore maybe you can replace '//' with a more explicite XPath
expression.
<xsl:variable name="AttrName" select="name()"/>
<xsl:choose>
<xsl:when test="bitmask:DeCode(current(), 2) " >
<xsl:variable name="Pos" >
<xsl:value-of select="MapKey/@*[name() =
$AttrName]" />
</xsl:variable>
Here you are creating a Result Tree Fragment, that later has to be
converted into a string. I think it's better to write
<xsl:variable name="Pos" select="MapKey/@*[name() = $AttrName]"/>
to have already a string stored in the variable.
2 - (<xsl:value-of select="$Pos" />)(<xsl:value-of
select="$AttrName" />) <xsl:value-of select="$Key/attribute::*[$Pos]" />
</xsl:when>
<xsl:when test="bitmask:DeCode(current(), 4) " >
<xsl:variable name="Pos" >
<xsl:value-of select="MapMD/attribute::*[name() =
$AttrName]" />
</xsl:variable>
Same here.
4(<xsl:value-of select="$Pos" />)(<xsl:value-of
select="$AttrName" />) <xsl:value-of select="$Market/attribute::*[position()
= $Pos]" />
Again attributes and position(). Try to refer to attributes by their
name - if possible in any way.
</xsl:when>
</xsl:choose>
<xsl:if test = "position() != last()"> | </xsl:if>
</xsl:for-each>
</xsl:attribute>
Regards,
Joerg
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list