This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Hopefully not a terribly silly question


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]