Get attribute from different level : Attribute « XSLT stylesheet « XML






Get attribute from different level

File: Data.xml

<data grape="A">
  <winery year="1998">B</winery>
</data>

File: Transform.xslt

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  version="1.0">
  <xsl:output method="xml" omit-xml-declaration="yes" indent="no" />

  <xsl:template match="winery">
    <wine>
      <xsl:value-of select="@year" />
      <xsl:text/>
      <xsl:value-of select="../@grape" />
    </wine>
  </xsl:template>

</xsl:stylesheet>

Output:


  <wine>1998A</wine>

 








Related examples in the same category

1.compare attribute value
2.List the attribute names and values
3.if there is an attribute
4.Get value of attribute with @
5.select node by attribute value
6.Set attribute value in tranformation
7.attribute omitted
8.get attribute name