Get sibling with ../ : parent « XSLT stylesheet « XML






Get sibling with ../


File: Data.xml

<vintage>
  <year>1998</year>
  <wine grape="B">
    <winery>A</winery>
  </wine>
</vintage>
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="wine">
    <wine varietal="{@grape}" brand="{winery}" year="{../year}" />
  </xsl:template>

  <xsl:template match="year" />

  
</xsl:stylesheet>

Output:


  
  <wine varietal="B" brand="A" year="1998"/>

 








Related examples in the same category

1.Use .. to indicate level
2.Don't output text nodes unless explicitly told to
3.Select element out of parent tag