thursday Posted February 25, 2006 Share Posted February 25, 2006 I was wondering if it would be possible to change the current XPath, a single time. For example, <xsl:for-each select="___"> changes the XPath such that each item is effectively treated as the root. I was wondering if there was a way to do this once.My goal was to be able to print the current "path" a node is in. Say the above function is called like "with"... something like the following: <xsl:template name="qname"> <xsl:with select="../"> <xsl:call-template name="qname"/> </xsl:with> <xsl:text>/</xsl:text><xsl:value-of select="@name"></xsl:template> Which ideally, when called, in the below xml file... <element name="a"> <element name="b"> </element> <element name="c"> <element name="d"> </element> </element></element> When called from the element who's name is "d", would output:a/c/dAnyways, does anybody have any idea how to do either of these problems?? Link to comment Share on other sites More sharing options...
thursday Posted February 28, 2006 Author Share Posted February 28, 2006 Ok, I have come up with a solution, however I get an error that I doubt I should. Here is the XML file again: <?xml-stylesheet type="text/xsl" href="namepath_xsl"?><element name="A"> <element name="B"> </element> <element name="C"> <element name="D"> </element> </element></element> The proposed XSLT solution looks like this: <?xml version="1.0" encoding="ISO-8859-1"?><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fn="http://www.w3.org/2005/xpath-functions"> <xsl:output method='html' version='1.0' encoding='UTF-8' indent='yes'/> <xsl:template match="/"> <html> <body> <xsl:apply-templates/> </body> </html> </xsl:template> <xsl:template match="element"> <p> Element: "<xsl:value-of select="@name"/>"<br/> Path: "<xsl:call-template name="pathname"/>" </p> <xsl:apply-templates/> </xsl:template> <xsl:template name="pathname"> <xsl:param name="source" select="."/> <xsl:if test="$source != fn:root()"> <xsl:call-template name="pathname"> <xsl:with-param name="source" select="$source/../."/> </xsl:call-template> </xsl:if> <xsl:text>/</xsl:text><xsl:value-of select="$source/@name"/> </xsl:template></xsl:stylesheet> However, this returns in error in IE6. This error is shown below. Namespace 'http://www.w3.org/2005/xpath-functions' does not contain any functions.I have tried both "http://www.w3.org/2005/xpath-functions" as well as "http://www.w3.org/2005/02/xpath-functions" and I still get this error. Any help would be greatly appreciated!! Thanks! Link to comment Share on other sites More sharing options...
boen_robot Posted February 28, 2006 Share Posted February 28, 2006 Try not using the fn: prefix. By the way, I do get that error also. Not using the prefix helps on only some of the XPath functions. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now