Re: [xsl] Way to print the current context?

Subject: Re: [xsl] Way to print the current context?
From: "Martin Honnen martin.honnen@xxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 24 Apr 2025 22:58:24 -0000
On 25/04/2025 00:40, dvint@xxxxxxxxx wrote:
oXygen provides a nice utility where you place your cuursor on an
element and it will give you an xpath to that element.

/fn:map/fn:array[1]/fn:map[2]/fn:array[1]/fn:map[1]/fn:map[2]/fn:string[2]


It doesn't give you any of the attribute values that are on the various elements for selecting, but it does give you a good underztanding of where you are on the tree.

I have this function where I pass the current context to look up a
value based upon which element I'm in.

<xsl:function name="ping:find_description_filepath">
B  <xsl:param name="CONTEXT"/>
B  <xsl:choose>
B B B B B B  <xsl:when test="$CONTEXT/j:string[@key='description']">
B B B B B B B B B B  <xsl:value-of
select="$CONTEXT/j:string[@key='description']"/>
B B B B B B  </xsl:when>
B B B B <xsl:when

test="$CONTEXT/j:array[@key='item']/j:map[1]/j:map[@key='request']/j:string[@
key='description']">
B B B B B B B <xsl:value-of

select="$CONTEXT/j:array[@key='item']/j:map[1]/j:map[@key='request']/j:string
[@key='description']"/>
B B B B B B  </xsl:when>
B B B B B B  <xsl:otherwise>
B B B B B B B B  <xsl:message>ERROR: find_description_filepath() didn't
resolve "<xsl:value-of
select="$CONTEXT/j:string[@key='name']"/>"</xsl:message>
B B B B B  </xsl:otherwise>
B B  </xsl:choose>
B </xsl:function>

In the error message I have giveen another value to help locate the
issue, but I'd rather get something like the oXygen output as
something is going wrong. I've tested my xpath in the Xpath editor and
it does match content properly for some of the thing's I've tested,
but it isn't working when I run it from the stylesheet.



I am not sure how you expect us to tell what goes wrong if you don't show the function call and the context node.

As for outputting an XPath expression, there is fn:path (rather verbose
in XPath 3 as it carries the namespace literally but XPath 4 will allow
you to avoid that). And of course in various context like Schematron
people have written XSLT functions or templates to construct a path
before XPath 3 introduced a function for that.

Current Thread