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

Subject: Re: [xsl] Way to print the current context?
From: "Wendell Piez wapiez@xxxxxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Fri, 25 Apr 2025 13:00:40 -0000
Hello,

Just adding the obvious point that if you write yourself a function or set
of templates to write an XPath (as Dmitre has done) you can also tune it to
write better paths ('better' being relative to your case).

Templates make this pretty easy too and a nice exercise for
beginner-intermediates.

Regards, Wendell

On Thu, Apr 24, 2025 at 9:11b/PM Dimitre Novatchev dnovatchev@xxxxxxxxx <
xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:

> 1. The standard XPath 3 function fn:path
>
> 2. This XSLT transformation I wrote years ago:
>
https://stackoverflow.com/questions/4746299/generate-get-xpath-from-xml-in-ja
va/4747858#4747858
>
> Thanks,
> Dimitre.
>
> On Thu, Apr 24, 2025 at 3:40b/PM dvint@xxxxxxxxx <
> xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> 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">
>>    <xsl:param name="CONTEXT"/>
>>    <xsl:choose>
>>         <xsl:when test="$CONTEXT/j:string[@key='description']">
>>             <xsl:value-of
>> select="$CONTEXT/j:string[@key='description']"/>
>>         </xsl:when>
>>         <xsl:when
>>
>>
test="$CONTEXT/j:array[@key='item']/j:map[1]/j:map[@key='request']/j:string[@
key='description']">
>>             <xsl:value-of
>>
>>
select="$CONTEXT/j:array[@key='item']/j:map[1]/j:map[@key='request']/j:string
[@key='description']"/>
>>         </xsl:when>
>>         <xsl:otherwise>
>>           <xsl:message>ERROR: find_description_filepath() didn't resolve
>> "<xsl:value-of select="$CONTEXT/j:string[@key='name']"/>"</xsl:message>
>>        </xsl:otherwise>
>>     </xsl:choose>
>>   </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.
>>
>> ..dan
>>
>>
>>
>
>
> XSL-List info and archive <http://www.mulberrytech.com/xsl/xsl-list>
> EasyUnsubscribe <http://lists.mulberrytech.com/unsub/xsl-list/174322> (by
> email <>)
>


--
...Wendell Piez... ...wendell -at- nist -dot- gov...
...wendellpiez.com... ...pellucidliterature.org... ...pausepress.org...
...github.com/wendellpiez... ...gitlab.coko.foundation/wendell...

Current Thread