SitePoint Sponsor

User Tag List

Results 1 to 1 of 1

Threaded View

  1. #1
    SitePoint Wizard Pepejeria's Avatar
    Join Date
    Jan 2005
    Location
    Too far up north
    Posts
    1,566
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    RESOLVED: Using param value in xpath

    I have the following
    Code:
    <?xml version="1.0"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="html" indent="yes" encoding="UTF-8"/>
    <xsl:param name="myvar"/>
    
    <xsl:template match="/">
    	<html>
    	<body>
    		<xsl:for-each select="strings/$myvar">
    			<p><xsl:value-of select="."/></p>
    		</xsl:for-each>
    
    	</body>
    	</html>
    </xsl:template>
    
    </xsl:stylesheet>
    What i want to do is to use the $myvar in the xpath expression. Its marked in bold, but that gives me an error. I tried the concat function, but that did also didnt work. What am I doing wrong?

    UPDATE, found the following solution:
    Code:
    <xsl:param name="query"/>
    
    <xsl:template match="/">
    	<html>
    	<body>
    
    		<xsl:for-each select="/strings/*[name()=$query]">
    			<p><xsl:value-of select="."/></p>
    		</xsl:for-each>
    	
    	</body>
    	</html>
    </xsl:template>
    Last edited by Pepejeria; Jul 6, 2005 at 05:21.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •