Subject: Re: [xsl] XPath expression which converts the output of path() into an abbreviated path? From: "Norm Tovey-Walsh ndw@xxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> Date: Wed, 17 Aug 2022 12:52:24 -0000 |
> I am using the path() function and it is generating paths like this: > > /Q{}AeroPublication[1]/Q{}airports[1]/Q{}airport[1]/Q{}icaoCode[1] > > Now I want to convert that full path into an abbreviated path, consisting of just the last 3 names: > > airports/airport/icaoCode > > I can write a bunch of XSLT code that does this conversion. But is > there an XPath expression which does it? Off the top of my head, you can replace bQ{}b and b[1]b with the empty string, tokenize on b/b, get the last three members, and string-join them back together with b/b. Youbll have to exercise a little more care if the elements might be in a namespace or if you might get some other index (b[2]b for example). This works, but I canbt immediately think of a way to avoid the $parts variable. But someone cleverer than me will probably post a purely functional answer thatbs eluding me. <xsl:variable name="path" select="'/Q{}AeroPublication[1]/Q{}airports[1]/Q{}airport[1]/ Q{}icaoCode[1]'"/> <xsl:variable name="parts" select="replace($path, 'Q\{\}', '') => replace('\[\d+\]', '') => tokenize('/')"/> <xsl:sequence select="string-join($parts[count($parts) - position() lt 3], '/')"/> Be seeing you, norm -- Norman Tovey-Walsh <ndw@xxxxxxxxxx> https://nwalsh.com/ > He that will not apply new remedies must expect new evils; for time is > the great innovator.--Sir Francis Bacon [demime 1.01d removed an attachment of type application/pgp-signature which had a name of signature.asc]
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] XPath expression which co, Graydon graydon@xxxx | Thread | Re: [xsl] XPath expression which co, Norm Tovey-Walsh ndw |
Re: [xsl] XPath expression which co, Martin Honnen martin | Date | Re: [xsl] XPath expression which co, Norm Tovey-Walsh ndw |
Month |