Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

to retrieve attributes from an xml file by refereing that file in one xsl file

Tags:

xslt

consider my 'destinationURLLookUp.xml' file has the following structure

           <?xml version="1.0" encoding="UTF-8"?>
               <destinationURLs xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
              <destinationURL name="Default Page" value="/abc/ab"/>
                     <destinationURL name="Home Page" value="/abc/ac"/>

                </destinationURLs>

I'm loading this file in my XSLT using the following XSLT code and have to retrieve the corresponding 'name' attribute for the 'value' that i'm processing for the

            <destinationURL> 

tag.

XSLT snippet that i have tried

        <xsl:variable name="prop" select="document('destinationURLLookUp.xml')"/>
                <xsl:variable name="rep2" select="$prop/destinationURLs/destinationURL[@value=@url]/@name"/>
                <xsl:value-of select="$rep2" />

where @url is the url value that i will get which matches the 'value' attibute of

               <destinationURL> 

tag. I'm unable to get the output.Can i get the relative xpath for accessing 'name' attribute for the corrsponding 'value' matched.

tried with $prop/destinationURLs/destinationURL[@value=@url]/@name shown above.

like image 317
User 4.5.5 Avatar asked Nov 26 '25 14:11

User 4.5.5


1 Answers

I think you are just missing to explicitly specify the template current contenxt for the @url attribute. The correct XPath depends by the template where your instruction is placed.

I'm speaking about something like this:

<xsl:variable name="rep2" 
 select="$prop/destinationURLs/destinationURL[@value=current()/@url]/@name"/>

Do note current()/@url.

like image 196
Emiliano Poggi Avatar answered Nov 30 '25 23:11

Emiliano Poggi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!