Get value with current() : current « XSLT stylesheet « XML

XML
1. CSS Style
2. SVG
3. XML Schema
4. XQuery
5. XSLT stylesheet
Java
XML Tutorial
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / C Sharp
C# / CSharp Tutorial
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
XML » XSLT stylesheet » current 
Get value with current()


File: Data.xml

<?xml version="1.0"?>
<booklist>
  <book category="S">
    <title>title 1</title>
    <author>author 1</author>
  </book>
  <book category="FC">
    <title>title 2</title>
    <author>author 1</author>
  </book>
  <book category="FC">
    <title>title 3</title>
    <author>author 1</author>
  </book>
  <book category="CS">
    <title>title 4</title>
    <author>author 1</author>
    <author>author 2</author>
    <author>author 3</author>
    <author>author 4</author>
  </book>
</booklist>


File: Transform.xslt

<?xml version="1.0"?>
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  version="2.0" xmlns:book="books.uri" exclude-result-prefixes="book">

  <xsl:template match="/">
    <html>
      <body>
        <xsl:for-each select="//book">
          <h1>
            <xsl:value-of select="title" />
          </h1>
          <p>
            Category:
            <xsl:value-of select="$categories/category[@code=current()/@category]/@desc" />
          </p>
        </xsl:for-each>
      </body>
    </html>
  </xsl:template>

  <xsl:variable name="categories">
    <category code="S" desc="Science" />
    <category code="CS" desc="Computing" />
    <category code="FC" desc="Children's Fiction" />
  </xsl:variable>

</xsl:transform>

Output:

<html>
   <body>
      <h1>title 1</h1>
      <p>
                     Category:
                     Science
      </p>
      <h1>title 2</h1>
      <p>
                     Category:
                     Children's Fiction
      </p>
      <h1>title 3</h1>
      <p>
                     Category:
                     Children's Fiction
      </p>
      <h1>title 4</h1>
      <p>
                     Category:
                     Computing
      </p>
   </body>
</html>

 
Related examples in the same category
www.java2java.com | Contact Us
Copyright 2010 - 2030 Java Source and Support. All rights reserved.
All other trademarks are property of their respective owners.