I have a xml like this and I want the attribute which is defined in the “title” using XSL file.
I want to retrieve the value even if I change the elements
- catalog with books
- cd with book
XML:
<catalog>
<cd>
<title att="abce" att2="false">Empire Burlesque</title>
<artist>Bob Dylan</artist>
<country>USA</country>
<company>Columbia</company>
<price>10.90</price>
<year>1985</year>
</cd>
</catalog>
I tried this method to get att value
<xsl:variable name="outermostElementName" select="catalog/cd/title/attribute::att"/>
but this is specific to this XML only I want it to be genric
Is there any way?
Given your current xsl:variable, I think you could use one of the following to more generic
or
The first one assumes the root element is always called catalog. The second one does not depend on an ancestor nodes, but will pick up the title element at any level in the XML.