[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
Hi Morgan,
Morgan Goeller wrote:
No, you don't need an eval() function (except in your approach) so yes, you are approaching it incorrectly - but you're very nearly there.
The following does what you want:
--
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output indent="yes"/>
<xsl:template match="/">
<xsl:for-each select="/result/row">
<xsl:for-each select="./column">
<xsl:call-template name="print_name"/>
</xsl:for-each>
</xsl:for-each>
</xsl:template>
<xsl:template name="print_name">
<xsl:choose>
<xsl:when test="@name">Name = <xsl:value-of select="@name"/>
</xsl:when>
<xsl:otherwise>
<xsl:variable name="p" select="position()" />
Name <xsl:value-of select="position()"/>= <xsl:value-of select="/result/row[1]/column[position() = $p]/@name"/>
</xsl:otherwise>
</xsl:choose>
Value <xsl:value-of select="position()"/>=<xsl:value-of select="."/>
</xsl:template>
</xsl:stylesheet>
--
as you can see, the main difference is that I've replaced your attempt to concat() and (implictly) eval() a dynamic (and therefore illegal) XPath expression by a static XPath expression which gets its dynamic value from a variable. In fact you could also use
select="/result/row[1]/column[$p]/@name"
though this is slghtly less clear.
Hope this helps -
Francis.
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Re: [xsl] Hopefully not a terribly silly question
Subject: Re: [xsl] Hopefully not a terribly silly question From: Francis Norton <francis@xxxxxxxxxxx> Date: Thu, 03 Jan 2002 18:27:40 +0000 |
Hi Morgan,
Morgan Goeller wrote:
Unfortunately, I get a the literal string result of the concat() function, instead of the actual data value. Is there some sort of eval() function that I need to use? Am I approaching this incorrectly?
No, you don't need an eval() function (except in your approach) so yes, you are approaching it incorrectly - but you're very nearly there.
The following does what you want:
--
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output indent="yes"/>
<xsl:template match="/">
<xsl:for-each select="/result/row">
<xsl:for-each select="./column">
<xsl:call-template name="print_name"/>
</xsl:for-each>
</xsl:for-each>
</xsl:template>
<xsl:template name="print_name">
<xsl:choose>
<xsl:when test="@name">Name = <xsl:value-of select="@name"/>
</xsl:when>
<xsl:otherwise>
<xsl:variable name="p" select="position()" />
Name <xsl:value-of select="position()"/>= <xsl:value-of select="/result/row[1]/column[position() = $p]/@name"/>
</xsl:otherwise>
</xsl:choose>
Value <xsl:value-of select="position()"/>=<xsl:value-of select="."/>
</xsl:template>
</xsl:stylesheet>
--
as you can see, the main difference is that I've replaced your attempt to concat() and (implictly) eval() a dynamic (and therefore illegal) XPath expression by a static XPath expression which gets its dynamic value from a variable. In fact you could also use
select="/result/row[1]/column[$p]/@name"
though this is slghtly less clear.
Hope this helps -
Francis.
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Hopefully not a terribly sill, Morgan Goeller | Thread | Re: [xsl] Hopefully not a terribly , Wendell Piez |
[xsl] Postional predicates de-mysti, Evan Lenz | Date | Re: [xsl] remaining problem w/ dyn , Gunther Schadow |
Month |
Keywords