1 / 45

xsl:for-each

xsl:for-each. The xsl:for-each element allows for repeat processing of same sibling elements. It is ideal for producing table-like output in the output document tree. <xsl:template match=“node-value”> <xsl:for-each> <!-- statements go here --> </xsl:for-each> </xsl:template>.

kioko
Download Presentation

xsl:for-each

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. xsl:for-each • The xsl:for-each element allows for repeat processing of same sibling elements. • It is ideal for producing table-like output in the output document tree. <xsl:template match=“node-value”> <xsl:for-each> <!-- statements go here --> </xsl:for-each> </xsl:template>

  2. Specifying Same Nodes • In order for the xsl:for-each elements to output content to the output document tree for each unique node, we must include the select attribute value. <xsl:template match=“node-value”> <xsl:for-each select=“node-value”> <!-- statements go here --> </xsl:for-each> </xsl:template>

  3. xsl:variable • The xsl:variable element allows us to store a value that we can use at run time. • Variables come in two forms – global and local. • A Global variable is declared at the top of the document and can only contain one value for the entire transformation. • A Local variable is contained within a template and contains a different value each time the template is accessed.

  4. xsl:variable • A xsl:variable element may be used as both a container and empty element with the difference being the presence or absence of the select attribute. <xsl:variable name=“temp”>abc</xsl:variable> <xsl:variable name=“temp”><xsl:value-of select=“/books/book[1]/title”/></xsl:variable> <xsl:variable name=“temp” select=“/books/book[1]/title”/>

  5. Specifying Same Nodes • In order for the xsl:for-each elements to output content to the output document tree for each unique node, we must include the select attribute value. <xsl:template match=“node-value”> <xsl:for-each select=“node-value”> <!-- statements go here --> </xsl:for-each> </xsl:template>

  6. XSL XPath Functions

  7. An Example using normalize-space() The Transformation Document…. <xsl:stylesheet version="1.0“ xmlns:xsl=“http://www.w3.org/1999/XSL/Transform”> <xsl:template match=“sample_doc”> __normalize-space()__ normalize-space('CIS97yt') = '<xsl:value-of select="normalize- space(' CIS 97 yt ')"/>' normalize-space(sample-node-set) = '<xsl:value-of select="normalize-space(sample-node-set)"/>' </xsl:template> </xsl:stylesheet>

  8. String XPath Functions

  9. String XPath Functions

  10. String XPath Functions

  11. Source Document The Source XML Document…. <?xml version="1.0"?> <!-- Sample XML Document --> <sample-doc xml:lang="en"> <sample-node-set> <node-set node="1">10</node-set> <node-set node="2">20</node-set> <node-set node="3">30</node-set> </sample-node-set> </sample-doc>

  12. An Example using string() The Transformation Document…. <xsl:stylesheet version="1.0“ xmlns:xsl=“http://www.w3.org/1999/XSL/Transform”> <xsl:template match=“sample_doc”> __string()__ string(true()) = <xsl:value-of select="string(true())"/> string(false()) = <xsl:value-of select="string(false())"/> </xsl:template> </xsl:stylesheet>

  13. The Results…. The Output Document…. __string()__ string(true()) = true string(false()) = false

  14. An Example using string() The Transformation Document…. <xsl:stylesheet version="1.0“ xmlns:xsl=“http://www.w3.org/1999/XSL/Transform”> <xsl:template match=“sample_doc”> __string()__ string(0) = <xsl:value-of select="string(0)"/> string(1) = <xsl:value-of select="string(1)"/> string(1.1) = <xsl:value-of select="string(1.1)"/> string(-1.1) = <xsl:value-of select="string(-1.1)"/> </xsl:template> </xsl:stylesheet>

  15. The Results…. The Output Document…. __string()__ string(0) = 0 string(1) = 1 string(1.1) = 1.1 string(-1.1) = -1.1

  16. An Example using string() The Transformation Document…. <xsl:stylesheet version="1.0“ xmlns:xsl=“http://www.w3.org/1999/XSL/Transform”> <xsl:template match=“sample_doc”> __string()__ string('') = <xsl:value-of select="string('')"/> string('CIS97yt') = <xsl:value-of select="string('CIS97yt')"/> string('a') = <xsl:value-of select="string('a')"/> string('97') = <xsl:value-of select="string('97')"/> string('9 7') = <xsl:value-of select="string('9 7')"/> string('9+7') = <xsl:value-of select="string('9+7')"/> </xsl:template> </xsl:stylesheet>

  17. The Results…. The Output Document…. __string()__ string('') = string('CIS97yt') = CIS97yt string('a') = a string('97') = 97 string('9 7') = 9 7 string('9+7') = 9+7

  18. An Example using string() The Transformation Document…. <xsl:stylesheet version="1.0“ xmlns:xsl=“http://www.w3.org/1999/XSL/Transform”> <xsl:template match=“sample_doc”> __string()__ string(node-set) = <xsl:value-of select="string(node-set)"/> string(sample-node-set) = <xsl:value-of select="string(sample-node-set)"/> string(sample-node-set/node-set) = <xsl:value-of select="string(sample-node-set/node-set)"/> </xsl:template> </xsl:stylesheet>

  19. The Results…. The Output Document…. __string()__ string(node-set) = string(sample-node-set) = 10 20 30 string(sample-node-set/node-set) = 10

  20. The Results…. The Output Document…. __normalize-space()__ normalize-space('CIS97yt') = 'CIS 97 yt' normalize-space(sample-node-set) = '10 20 30'

  21. Boolean XPath Functions

  22. Source Document The Source XML Document…. <?xml version="1.0"?> <!-- Sample XML Document --> <sample-doc xml:lang="en"> <sample-node-set> <node-set node="1">10</node-set> <node-set node="2">20</node-set> <node-set node="3">30</node-set> </sample-node-set> </sample-doc>

  23. An Example using boolean() The Transformation Document…. <xsl:stylesheet version="1.0“ xmlns:xsl=“http://www.w3.org/1999/XSL/Transform”> <xsl:template match=“sample_doc”> __boolean(boolean)__ boolean(false()) = <xsl:value-of select=“boolean(false())”/> boolean(true()) = <xsl:value-of select=“boolean(true())”/> </xsl:template> </xsl:stylesheet>

  24. The Results…. The Output Document…. __boolean(boolean)__ boolean(false()) = false boolean(true()) = true

  25. An Example using boolean() The Transformation Document…. <xsl:stylesheet version="1.0“ xmlns:xsl=“http://www.w3.org/1999/XSL/Transform”> <xsl:template match=“sample_doc”> __boolean(number)__ boolean(0) = <xsl:value-of select=“boolean(0)”/> boolean(1) = <xsl:value-of select=“boolean(1)”/> boolean(1.1) = <xsl:value-of select=“boolean(1.1)”/> boolean(-1.1) = <xsl:value-of select=“boolean(-1.1)”/> </xsl:template> </xsl:stylesheet>

  26. The Results…. The Output Document…. __boolean(number)__ boolean(0) = false boolean(1) = true boolean(1.1) = true boolean(-1.1) = true

  27. An Example using boolean() The Transformation Document…. <xsl:stylesheet version="1.0“ xmlns:xsl=“http://www.w3.org/1999/XSL/Transform”> <xsl:template match=“sample_doc”> __boolean(string)__ boolean('') = <xsl:value-of select="boolean('')"/> boolean('CS97yt') = <xsl:value-of select="boolean('CS97yt')"/> boolean('a') = <xsl:value-of select="boolean('a')"/> boolean('97') = <xsl:value-of select="boolean('97')"/> boolean('9 7') = <xsl:value-of select="boolean('9 7')"/> boolean('9+7') = <xsl:value-of select="boolean('9+7')"/> </xsl:template> </xsl:stylesheet>

  28. The Results…. The Output Document…. __boolean(string)__ boolean('') = false boolean('CIS97yt') = true boolean('a') = true boolean('97') = true boolean('9 7') = true boolean('9+7') = true

  29. An Example using boolean() The Transformation Document…. <xsl:stylesheet version="1.0“ xmlns:xsl=“http://www.w3.org/1999/XSL/Transform”> <xsl:template match=“sample_doc”> __boolean(node-set)__ boolean(node-set) = <xsl:value-of select="boolean(node-set)"/> boolean(sample-node-set) = <xsl:value-of select="boolean(sample-node-set)"/> boolean(sample-node-set/node-set) = <xsl:value-of select="boolean(sample-node-set/node-set)"/> </xsl:template> </xsl:stylesheet>

  30. The Results…. The Output Document…. __boolean(node-set)__ boolean(node-set) = false boolean(sample-node-set) = true boolean(sample-node-set/node-set) = true

  31. An Example using not() The Transformation Document…. <xsl:stylesheet version="1.0“ xmlns:xsl=“http://www.w3.org/1999/XSL/Transform”> <xsl:template match=“sample_doc”> __not()__ not(true()) = <xsl:value-of select="not(true())"/> not(false()) = <xsl:value-of select="not(false())"/> </xsl:template> </xsl:stylesheet>

  32. The Results…. The Output Document…. __not()__ not(true()) = false not(false()) = true

  33. An Example using not() The Transformation Document…. <xsl:stylesheet version="1.0“ xmlns:xsl=“http://www.w3.org/1999/XSL/Transform”> <xsl:template match=“sample_doc”> __not(number)__ not(0) = <xsl:value-of select=“not(0)”/> not(1) = <xsl:value-of select=“not(1)”/> not(1.1) = <xsl:value-of select=“not(1.1)”/> not(-1.1) = <xsl:value-of select=“not(-1.1)”/> </xsl:template> </xsl:stylesheet>

  34. The Results…. The Output Document…. __not()__ not(0) = true not(1) = false not(1.1) = false not(-1.1) = false

  35. An Example using not() The Transformation Document…. <xsl:stylesheet version="1.0“ xmlns:xsl=“http://www.w3.org/1999/XSL/Transform”> <xsl:template match=“sample_doc”> __not(string)__ not('') = <xsl:value-of select="not('')"/> not('CS97yt') = <xsl:value-of select="not('CS97yt')"/> not('a') = <xsl:value-of select="not('a')"/> not('97') = <xsl:value-of select="not('97')"/> not('9 7') = <xsl:value-of select="not('9 7')"/> not('9+7') = <xsl:value-of select="not('9+7')"/> </xsl:template> </xsl:stylesheet>

  36. The Results…. The Output Document…. __not()__ not('') = true not('CIS97yt') = false not('a') = false not('97') = false not('9 7') = false not('9+7') = false

  37. An Example using not() The Transformation Document…. <xsl:stylesheet version="1.0“ xmlns:xsl=“http://www.w3.org/1999/XSL/Transform”> <xsl:template match=“sample_doc”> __not(node-set)__ not(node-set) = <xsl:value-of select="not(node-set)"/> not(sample-node-set) = <xsl:value-of select="not(sample-node-set)"/> not(sample-node-set/node-set) = <xsl:value-of select="not(sample-node-set/node-set)"/> </xsl:template> </xsl:stylesheet>

  38. The Results…. The Output Document…. __not()__ not(node-set) = true not(sample-node-set) = false not(sample-node-set/node-set) = false

  39. An Example using true() The Transformation Document…. <xsl:stylesheet version="1.0“ xmlns:xsl=“http://www.w3.org/1999/XSL/Transform”> <xsl:template match=“sample_doc”> __true()__ true() = <xsl:value-of select=“true()”/> </xsl:template> </xsl:stylesheet>

  40. The Results…. The Output Document…. __true()__ true() = true

  41. An Example using false() The Transformation Document…. <xsl:stylesheet version="1.0“ xmlns:xsl=“http://www.w3.org/1999/XSL/Transform”> <xsl:template match=“sample_doc”> __false()__ false() = <xsl:value-of select=“false()”/> </xsl:template> </xsl:stylesheet>

  42. The Results…. The Output Document…. __false()__ false() = false

  43. An Example using lang() The Transformation Document…. <xsl:stylesheet version="1.0“ xmlns:xsl=“http://www.w3.org/1999/XSL/Transform”> <xsl:template match=“sample_doc”> __lang()__ lang(‘en’) = <xsl:value-of select=“lang(‘en’)”/> lang(‘fr’) = <xsl:value-of select=“lang(‘fr’)”/> </xsl:template> </xsl:stylesheet>

  44. The Results…. The Output Document…. __lang()__ lang('en') = true lang('fr') = false

More Related