>> English << | Français | Deutsch | Magyar | 中文 | Polski | ZVON > Tutorials > XSLT Tutorial |
Intro / Search / ZVON |
>> Page 15 << | Prev | Next | Contents | Element Index |
XML Source
<source> <AAA id="a1" pos="start"> <BBB id="b1"/> <BBB id="b2"/> </AAA> <AAA id="a2"> <BBB id="b3"/> <BBB id="b4"/> <CCC id="c1"> <CCC id="c2"/> </CCC> <BBB id="b5"> <CCC id="c3"/> </BBB> </AAA> </source> Output
<table border="1" cellpadding="6"> <tr> <th colspan="2">Axis: child</th> </tr> <tr> <th>Element</th> <th>Node-set</th> </tr> <tr> <td>AAA id = a1</td> <td>b1b2</td> </tr> <tr> <td>BBB id = b1</td> <td/> </tr> <tr> <td>BBB id = b2</td> <td/> </tr> <tr> <td>AAA id = a2</td> <td>b3b4c1b5</td> </tr> <tr> <td>BBB id = b3</td> <td/> </tr> <tr> <td>BBB id = b4</td> <td/> </tr> <tr> <td>CCC id = c1</td> <td>c2</td> </tr> <tr> <td>CCC id = c2</td> <td/> </tr> <tr> <td>BBB id = b5</td> <td>c3</td> </tr> <tr> <td>CCC id = c3</td> <td/> </tr> </table> HTML view
|
XSLT stylesheet
<xsl:stylesheet version = '1.0'
xmlns:xsl='http://www.w3.org/1999/XSL/Transform'> <xsl:template match="/"> <table border="1" cellpadding="6"> <tr> <th colspan="2">Axis: child</th> </tr> <tr> <th>Element</th> <th>Node-set</th> </tr> <xsl:for-each select="/source//*"> <xsl:call-template name="print"/> </xsl:for-each> </table> </xsl:template> <xsl:template name="print"> <tr> <td> <xsl:value-of select="name()"/> <xsl:text> id = </xsl:text> <xsl:value-of select="./@id"/> </td> <td> <xsl:for-each select="child::*"> <xsl:value-of select="./@id"/> <xsl:text/> </xsl:for-each> </td> </tr> </xsl:template> </xsl:stylesheet> |
XML Source
<source> <AAA id="a1" pos="start"> <BBB id="b1"/> <BBB id="b2"/> </AAA> <AAA id="a2"> <BBB id="b3"/> <BBB id="b4"/> <CCC id="c1"> <CCC id="c2"/> </CCC> <BBB id="b5"> <CCC id="c3"/> </BBB> </AAA> </source> Output
<table border="1" cellpadding="6"> <tr> <th colspan="2">Axis: descendant</th> </tr> <tr> <th>Element</th> <th>Node-set</th> </tr> <tr> <td>AAA id = a1</td> <td>b1b2</td> </tr> <tr> <td>BBB id = b1</td> <td/> </tr> <tr> <td>BBB id = b2</td> <td/> </tr> <tr> <td>AAA id = a2</td> <td>b3b4c1c2b5c3</td> </tr> <tr> <td>BBB id = b3</td> <td/> </tr> <tr> <td>BBB id = b4</td> <td/> </tr> <tr> <td>CCC id = c1</td> <td>c2</td> </tr> <tr> <td>CCC id = c2</td> <td/> </tr> <tr> <td>BBB id = b5</td> <td>c3</td> </tr> <tr> <td>CCC id = c3</td> <td/> </tr> </table> HTML view
|
XSLT stylesheet
<xsl:stylesheet version = '1.0'
xmlns:xsl='http://www.w3.org/1999/XSL/Transform'> <xsl:template match="/"> <table border="1" cellpadding="6"> <tr> <th colspan="2">Axis: descendant</th> </tr> <tr> <th>Element</th> <th>Node-set</th> </tr> <xsl:for-each select="/source//*"> <xsl:call-template name="print"/> </xsl:for-each> </table> </xsl:template> <xsl:template name="print"> <tr> <td> <xsl:value-of select="name()"/> <xsl:text> id = </xsl:text> <xsl:value-of select="./@id"/> </td> <td> <xsl:for-each select="descendant::*"> <xsl:value-of select="./@id"/> <xsl:text/> </xsl:for-each> </td> </tr> </xsl:template> </xsl:stylesheet> |
XML Source
<source> <AAA id="a1" pos="start"> <BBB id="b1"/> <BBB id="b2"/> </AAA> <AAA id="a2"> <BBB id="b3"/> <BBB id="b4"/> <CCC id="c1"> <CCC id="c2"/> </CCC> <BBB id="b5"> <CCC id="c3"/> </BBB> </AAA> </source> Output
<table border="1" cellpadding="6"> <tr> <th colspan="2">Axis: parent</th> </tr> <tr> <th>Element</th> <th>Node-set</th> </tr> <tr> <td>AAA id = a1</td> <td>source</td> </tr> <tr> <td>BBB id = b1</td> <td>a1</td> </tr> <tr> <td>BBB id = b2</td> <td>a1</td> </tr> <tr> <td>AAA id = a2</td> <td>source</td> </tr> <tr> <td>BBB id = b3</td> <td>a2</td> </tr> <tr> <td>BBB id = b4</td> <td>a2</td> </tr> <tr> <td>CCC id = c1</td> <td>a2</td> </tr> <tr> <td>CCC id = c2</td> <td>c1</td> </tr> <tr> <td>BBB id = b5</td> <td>a2</td> </tr> <tr> <td>CCC id = c3</td> <td>b5</td> </tr> </table> HTML view
|
XSLT stylesheet
<xsl:stylesheet version = '1.0'
xmlns:xsl='http://www.w3.org/1999/XSL/Transform'> <xsl:template match="/"> <table border="1" cellpadding="6"> <tr> <th colspan="2">Axis: parent</th> </tr> <tr> <th>Element</th> <th>Node-set</th> </tr> <xsl:for-each select="/source//*"> <xsl:call-template name="print"/> </xsl:for-each> </table> </xsl:template> <xsl:template name="print"> <tr> <td> <xsl:value-of select="name()"/> <xsl:text> id = </xsl:text> <xsl:value-of select="./@id"/> </td> <td> <xsl:for-each select="parent::*"> <xsl:if test="not(@id)"> <xsl:value-of select="name()"/> </xsl:if> <xsl:value-of select="./@id"/> <xsl:text/> </xsl:for-each> </td> </tr> </xsl:template> </xsl:stylesheet> |
XML Source
<source> <AAA id="a1" pos="start"> <BBB id="b1"/> <BBB id="b2"/> </AAA> <AAA id="a2"> <BBB id="b3"/> <BBB id="b4"/> <CCC id="c1"> <CCC id="c2"/> </CCC> <BBB id="b5"> <CCC id="c3"/> </BBB> </AAA> </source> Output
<table border="1" cellpadding="6"> <tr> <th colspan="2">Axis: ancestor</th> </tr> <tr> <th>Element</th> <th>Node-set</th> </tr> <tr> <td>AAA id = a1</td> <td>source</td> </tr> <tr> <td>BBB id = b1</td> <td>sourcea1</td> </tr> <tr> <td>BBB id = b2</td> <td>sourcea1</td> </tr> <tr> <td>AAA id = a2</td> <td>source</td> </tr> <tr> <td>BBB id = b3</td> <td>sourcea2</td> </tr> <tr> <td>BBB id = b4</td> <td>sourcea2</td> </tr> <tr> <td>CCC id = c1</td> <td>sourcea2</td> </tr> <tr> <td>CCC id = c2</td> <td>sourcea2c1</td> </tr> <tr> <td>BBB id = b5</td> <td>sourcea2</td> </tr> <tr> <td>CCC id = c3</td> <td>sourcea2b5</td> </tr> </table> HTML view
|
XSLT stylesheet
<xsl:stylesheet version = '1.0'
xmlns:xsl='http://www.w3.org/1999/XSL/Transform'> <xsl:template match="/"> <table border="1" cellpadding="6"> <tr> <th colspan="2">Axis: ancestor</th> </tr> <tr> <th>Element</th> <th>Node-set</th> </tr> <xsl:for-each select="/source//*"> <xsl:call-template name="print"/> </xsl:for-each> </table> </xsl:template> <xsl:template name="print"> <tr> <td> <xsl:value-of select="name()"/> <xsl:text> id = </xsl:text> <xsl:value-of select="./@id"/> </td> <td> <xsl:for-each select="ancestor::*"> <xsl:if test="not(@id)"> <xsl:value-of select="name()"/> </xsl:if> <xsl:value-of select="./@id"/> <xsl:text/> </xsl:for-each> </td> </tr> </xsl:template> </xsl:stylesheet> |
XML Source
<source> <AAA id="a1" pos="start"> <BBB id="b1"/> <BBB id="b2"/> </AAA> <AAA id="a2"> <BBB id="b3"/> <BBB id="b4"/> <CCC id="c1"> <CCC id="c2"/> </CCC> <BBB id="b5"> <CCC id="c3"/> </BBB> </AAA> </source> Output
<table border="1" cellpadding="6"> <tr> <th colspan="2">Axis: following-sibling</th> </tr> <tr> <th>Element</th> <th>Node-set</th> </tr> <tr> <td>AAA id = a1</td> <td>a2</td> </tr> <tr> <td>BBB id = b1</td> <td>b2</td> </tr> <tr> <td>BBB id = b2</td> <td/> </tr> <tr> <td>AAA id = a2</td> <td/> </tr> <tr> <td>BBB id = b3</td> <td>b4c1b5</td> </tr> <tr> <td>BBB id = b4</td> <td>c1b5</td> </tr> <tr> <td>CCC id = c1</td> <td>b5</td> </tr> <tr> <td>CCC id = c2</td> <td/> </tr> <tr> <td>BBB id = b5</td> <td/> </tr> <tr> <td>CCC id = c3</td> <td/> </tr> </table> HTML view
|
XSLT stylesheet
<xsl:stylesheet version = '1.0'
xmlns:xsl='http://www.w3.org/1999/XSL/Transform'> <xsl:template match="/"> <table border="1" cellpadding="6"> <tr> <th colspan="2">Axis: following-sibling</th> </tr> <tr> <th>Element</th> <th>Node-set</th> </tr> <xsl:for-each select="/source//*"> <xsl:call-template name="print"/> </xsl:for-each> </table> </xsl:template> <xsl:template name="print"> <tr> <td> <xsl:value-of select="name()"/> <xsl:text> id = </xsl:text> <xsl:value-of select="./@id"/> </td> <td> <xsl:for-each select="following-sibling::*"> <xsl:if test="not(@id)"> <xsl:value-of select="name()"/> </xsl:if> <xsl:value-of select="./@id"/> <xsl:text/> </xsl:for-each> </td> </tr> </xsl:template> </xsl:stylesheet> |
XML Source
<source> <AAA id="a1" pos="start"> <BBB id="b1"/> <BBB id="b2"/> </AAA> <AAA id="a2"> <BBB id="b3"/> <BBB id="b4"/> <CCC id="c1"> <CCC id="c2"/> </CCC> <BBB id="b5"> <CCC id="c3"/> </BBB> </AAA> </source> Output
<table border="1" cellpadding="6"> <tr> <th colspan="2">Axis: preceding-sibling</th> </tr> <tr> <th>Element</th> <th>Node-set</th> </tr> <tr> <td>AAA id = a1</td> <td/> </tr> <tr> <td>BBB id = b1</td> <td/> </tr> <tr> <td>BBB id = b2</td> <td>b1</td> </tr> <tr> <td>AAA id = a2</td> <td>a1</td> </tr> <tr> <td>BBB id = b3</td> <td/> </tr> <tr> <td>BBB id = b4</td> <td>b3</td> </tr> <tr> <td>CCC id = c1</td> <td>b3b4</td> </tr> <tr> <td>CCC id = c2</td> <td/> </tr> <tr> <td>BBB id = b5</td> <td>b3b4c1</td> </tr> <tr> <td>CCC id = c3</td> <td/> </tr> </table> HTML view
|
XSLT stylesheet
<xsl:stylesheet version = '1.0'
xmlns:xsl='http://www.w3.org/1999/XSL/Transform'> <xsl:template match="/"> <table border="1" cellpadding="6"> <tr> <th colspan="2">Axis: preceding-sibling</th> </tr> <tr> <th>Element</th> <th>Node-set</th> </tr> <xsl:for-each select="/source//*"> <xsl:call-template name="print"/> </xsl:for-each> </table> </xsl:template> <xsl:template name="print"> <tr> <td> <xsl:value-of select="name()"/> <xsl:text> id = </xsl:text> <xsl:value-of select="./@id"/> </td> <td> <xsl:for-each select="preceding-sibling::*"> <xsl:if test="not(@id)"> <xsl:value-of select="name()"/> </xsl:if> <xsl:value-of select="./@id"/> <xsl:text/> </xsl:for-each> </td> </tr> </xsl:template> </xsl:stylesheet> |
XML Source
<source> <AAA id="a1" pos="start"> <BBB id="b1"/> <BBB id="b2"/> </AAA> <AAA id="a2"> <BBB id="b3"/> <BBB id="b4"/> <CCC id="c1"> <CCC id="c2"/> </CCC> <BBB id="b5"> <CCC id="c3"/> </BBB> </AAA> </source> Output
<table border="1" cellpadding="6"> <tr> <th colspan="2">Axis: following</th> </tr> <tr> <th>Element</th> <th>Node-set</th> </tr> <tr> <td>AAA id = a1</td> <td>a2b3b4c1c2b5c3</td> </tr> <tr> <td>BBB id = b1</td> <td>b2a2b3b4c1c2b5c3</td> </tr> <tr> <td>BBB id = b2</td> <td>a2b3b4c1c2b5c3</td> </tr> <tr> <td>AAA id = a2</td> <td/> </tr> <tr> <td>BBB id = b3</td> <td>b4c1c2b5c3</td> </tr> <tr> <td>BBB id = b4</td> <td>c1c2b5c3</td> </tr> <tr> <td>CCC id = c1</td> <td>b5c3</td> </tr> <tr> <td>CCC id = c2</td> <td>b5c3</td> </tr> <tr> <td>BBB id = b5</td> <td/> </tr> <tr> <td>CCC id = c3</td> <td/> </tr> </table> HTML view
|
XSLT stylesheet
<xsl:stylesheet version = '1.0'
xmlns:xsl='http://www.w3.org/1999/XSL/Transform'> <xsl:template match="/"> <table border="1" cellpadding="6"> <tr> <th colspan="2">Axis: following</th> </tr> <tr> <th>Element</th> <th>Node-set</th> </tr> <xsl:for-each select="/source//*"> <xsl:call-template name="print"/> </xsl:for-each> </table> </xsl:template> <xsl:template name="print"> <tr> <td> <xsl:value-of select="name()"/> <xsl:text> id = </xsl:text> <xsl:value-of select="./@id"/> </td> <td> <xsl:for-each select="following::*"> <xsl:if test="not(@id)"> <xsl:value-of select="name()"/> </xsl:if> <xsl:value-of select="./@id"/> <xsl:text/> </xsl:for-each> </td> </tr> </xsl:template> </xsl:stylesheet> |
XML Source
<source> <AAA id="a1" pos="start"> <BBB id="b1"/> <BBB id="b2"/> </AAA> <AAA id="a2"> <BBB id="b3"/> <BBB id="b4"/> <CCC id="c1"> <CCC id="c2"/> </CCC> <BBB id="b5"> <CCC id="c3"/> </BBB> </AAA> </source> Output
<table border="1" cellpadding="6"> <tr> <th colspan="2">Axis: preceding</th> </tr> <tr> <th>Element</th> <th>Node-set</th> </tr> <tr> <td>AAA id = a1</td> <td/> </tr> <tr> <td>BBB id = b1</td> <td/> </tr> <tr> <td>BBB id = b2</td> <td>b1</td> </tr> <tr> <td>AAA id = a2</td> <td>a1b1b2</td> </tr> <tr> <td>BBB id = b3</td> <td>a1b1b2</td> </tr> <tr> <td>BBB id = b4</td> <td>a1b1b2b3</td> </tr> <tr> <td>CCC id = c1</td> <td>a1b1b2b3b4</td> </tr> <tr> <td>CCC id = c2</td> <td>a1b1b2b3b4</td> </tr> <tr> <td>BBB id = b5</td> <td>a1b1b2b3b4c1c2</td> </tr> <tr> <td>CCC id = c3</td> <td>a1b1b2b3b4c1c2</td> </tr> </table> HTML view
|
XSLT stylesheet
<xsl:stylesheet version = '1.0'
xmlns:xsl='http://www.w3.org/1999/XSL/Transform'> <xsl:template match="/"> <table border="1" cellpadding="6"> <tr> <th colspan="2">Axis: preceding</th> </tr> <tr> <th>Element</th> <th>Node-set</th> </tr> <xsl:for-each select="/source//*"> <xsl:call-template name="print"/> </xsl:for-each> </table> </xsl:template> <xsl:template name="print"> <tr> <td> <xsl:value-of select="name()"/> <xsl:text> id = </xsl:text> <xsl:value-of select="./@id"/> </td> <td> <xsl:for-each select="preceding::*"> <xsl:if test="not(@id)"> <xsl:value-of select="name()"/> </xsl:if> <xsl:value-of select="./@id"/> <xsl:text/> </xsl:for-each> </td> </tr> </xsl:template> </xsl:stylesheet> |
XML Source
<source> <AAA id="a1" pos="start"> <BBB id="b1"/> <BBB id="b2"/> </AAA> <AAA id="a2"> <BBB id="b3"/> <BBB id="b4"/> <CCC id="c1"> <CCC id="c2"/> </CCC> <BBB id="b5"> <CCC id="c3"/> </BBB> </AAA> </source> Output
<table border="1" cellpadding="6"> <tr> <th colspan="2">Axis: attribute</th> </tr> <tr> <th>Element</th> <th>Node-set</th> </tr> <tr> <td>AAA id = a1</td> <td>idpos</td> </tr> <tr> <td>BBB id = b1</td> <td>id</td> </tr> <tr> <td>BBB id = b2</td> <td>id</td> </tr> <tr> <td>AAA id = a2</td> <td>id</td> </tr> <tr> <td>BBB id = b3</td> <td>id</td> </tr> <tr> <td>BBB id = b4</td> <td>id</td> </tr> <tr> <td>CCC id = c1</td> <td>id</td> </tr> <tr> <td>CCC id = c2</td> <td>id</td> </tr> <tr> <td>BBB id = b5</td> <td>id</td> </tr> <tr> <td>CCC id = c3</td> <td>id</td> </tr> </table> HTML view
|
XSLT stylesheet
<xsl:stylesheet version = '1.0'
xmlns:xsl='http://www.w3.org/1999/XSL/Transform'> <xsl:template match="/"> <table border="1" cellpadding="6"> <tr> <th colspan="2">Axis: attribute</th> </tr> <tr> <th>Element</th> <th>Node-set</th> </tr> <xsl:for-each select="/source//*"> <xsl:call-template name="print"/> </xsl:for-each> </table> </xsl:template> <xsl:template name="print"> <tr> <td> <xsl:value-of select="name()"/> <xsl:text> id = </xsl:text> <xsl:value-of select="./@id"/> </td> <td> <xsl:for-each select="attribute::*"> <xsl:if test="not(@id)"> <xsl:value-of select="name()"/> </xsl:if> <xsl:value-of select="./@id"/> <xsl:text/> </xsl:for-each> </td> </tr> </xsl:template> </xsl:stylesheet> |
XML Source
<source> <AAA id="a1" pos="start"> <BBB id="b1"/> <BBB id="b2"/> </AAA> <AAA id="a2"> <BBB id="b3"/> <BBB id="b4"/> <CCC id="c1"> <CCC id="c2"/> </CCC> <BBB id="b5"> <CCC id="c3"/> </BBB> </AAA> </source> Output
<table border="1" cellpadding="6"> <tr> <th colspan="2">Axis: namespace</th> </tr> <tr> <th>Element</th> <th>Node-set</th> </tr> <tr> <td>AAA id = a1</td> <td>xml</td> </tr> <tr> <td>BBB id = b1</td> <td>xml</td> </tr> <tr> <td>BBB id = b2</td> <td>xml</td> </tr> <tr> <td>AAA id = a2</td> <td>xml</td> </tr> <tr> <td>BBB id = b3</td> <td>xml</td> </tr> <tr> <td>BBB id = b4</td> <td>xml</td> </tr> <tr> <td>CCC id = c1</td> <td>xml</td> </tr> <tr> <td>CCC id = c2</td> <td>xml</td> </tr> <tr> <td>BBB id = b5</td> <td>xml</td> </tr> <tr> <td>CCC id = c3</td> <td>xml</td> </tr> </table> HTML view
|
XSLT stylesheet
<xsl:stylesheet version = '1.0'
xmlns:xsl='http://www.w3.org/1999/XSL/Transform'> <xsl:template match="/"> <table border="1" cellpadding="6"> <tr> <th colspan="2">Axis: namespace</th> </tr> <tr> <th>Element</th> <th>Node-set</th> </tr> <xsl:for-each select="/source//*"> <xsl:call-template name="print"/> </xsl:for-each> </table> </xsl:template> <xsl:template name="print"> <tr> <td> <xsl:value-of select="name()"/> <xsl:text> id = </xsl:text> <xsl:value-of select="./@id"/> </td> <td> <xsl:for-each select="namespace::*"> <xsl:if test="not(@id)"> <xsl:value-of select="name()"/> </xsl:if> <xsl:value-of select="./@id"/> <xsl:text/> </xsl:for-each> </td> </tr> </xsl:template> </xsl:stylesheet> |
XML Source
<source> <AAA id="a1" pos="start"> <BBB id="b1"/> <BBB id="b2"/> </AAA> <AAA id="a2"> <BBB id="b3"/> <BBB id="b4"/> <CCC id="c1"> <CCC id="c2"/> </CCC> <BBB id="b5"> <CCC id="c3"/> </BBB> </AAA> </source> Output
<table border="1" cellpadding="6"> <tr> <th colspan="2">Axis: self</th> </tr> <tr> <th>Element</th> <th>Node-set</th> </tr> <tr> <td>AAA id = a1</td> <td>a1</td> </tr> <tr> <td>BBB id = b1</td> <td>b1</td> </tr> <tr> <td>BBB id = b2</td> <td>b2</td> </tr> <tr> <td>AAA id = a2</td> <td>a2</td> </tr> <tr> <td>BBB id = b3</td> <td>b3</td> </tr> <tr> <td>BBB id = b4</td> <td>b4</td> </tr> <tr> <td>CCC id = c1</td> <td>c1</td> </tr> <tr> <td>CCC id = c2</td> <td>c2</td> </tr> <tr> <td>BBB id = b5</td> <td>b5</td> </tr> <tr> <td>CCC id = c3</td> <td>c3</td> </tr> </table> HTML view
|
XSLT stylesheet
<xsl:stylesheet version = '1.0'
xmlns:xsl='http://www.w3.org/1999/XSL/Transform'> <xsl:template match="/"> <table border="1" cellpadding="6"> <tr> <th colspan="2">Axis: self</th> </tr> <tr> <th>Element</th> <th>Node-set</th> </tr> <xsl:for-each select="/source//*"> <xsl:call-template name="print"/> </xsl:for-each> </table> </xsl:template> <xsl:template name="print"> <tr> <td> <xsl:value-of select="name()"/> <xsl:text> id = </xsl:text> <xsl:value-of select="./@id"/> </td> <td> <xsl:for-each select="self::*"> <xsl:if test="not(@id)"> <xsl:value-of select="name()"/> </xsl:if> <xsl:value-of select="./@id"/> <xsl:text/> </xsl:for-each> </td> </tr> </xsl:template> </xsl:stylesheet> |
XML Source
<source> <AAA id="a1" pos="start"> <BBB id="b1"/> <BBB id="b2"/> </AAA> <AAA id="a2"> <BBB id="b3"/> <BBB id="b4"/> <CCC id="c1"> <CCC id="c2"/> </CCC> <BBB id="b5"> <CCC id="c3"/> </BBB> </AAA> </source> Output
<table border="1" cellpadding="6"> <tr> <th colspan="2">Axis: descendant-or-self</th> </tr> <tr> <th>Element</th> <th>Node-set</th> </tr> <tr> <td>AAA id = a1</td> <td>a1b1b2</td> </tr> <tr> <td>BBB id = b1</td> <td>b1</td> </tr> <tr> <td>BBB id = b2</td> <td>b2</td> </tr> <tr> <td>AAA id = a2</td> <td>a2b3b4c1c2b5c3</td> </tr> <tr> <td>BBB id = b3</td> <td>b3</td> </tr> <tr> <td>BBB id = b4</td> <td>b4</td> </tr> <tr> <td>CCC id = c1</td> <td>c1c2</td> </tr> <tr> <td>CCC id = c2</td> <td>c2</td> </tr> <tr> <td>BBB id = b5</td> <td>b5c3</td> </tr> <tr> <td>CCC id = c3</td> <td>c3</td> </tr> </table> HTML view
|
XSLT stylesheet
<xsl:stylesheet version = '1.0'
xmlns:xsl='http://www.w3.org/1999/XSL/Transform'> <xsl:template match="/"> <table border="1" cellpadding="6"> <tr> <th colspan="2">Axis: descendant-or-self</th> </tr> <tr> <th>Element</th> <th>Node-set</th> </tr> <xsl:for-each select="/source//*"> <xsl:call-template name="print"/> </xsl:for-each> </table> </xsl:template> <xsl:template name="print"> <tr> <td> <xsl:value-of select="name()"/> <xsl:text> id = </xsl:text> <xsl:value-of select="./@id"/> </td> <td> <xsl:for-each select="descendant-or-self::*"> <xsl:if test="not(@id)"> <xsl:value-of select="name()"/> </xsl:if> <xsl:value-of select="./@id"/> <xsl:text/> </xsl:for-each> </td> </tr> </xsl:template> </xsl:stylesheet> |
XML Source
<source> <AAA id="a1" pos="start"> <BBB id="b1"/> <BBB id="b2"/> </AAA> <AAA id="a2"> <BBB id="b3"/> <BBB id="b4"/> <CCC id="c1"> <CCC id="c2"/> </CCC> <BBB id="b5"> <CCC id="c3"/> </BBB> </AAA> </source> Output
<table border="1" cellpadding="6"> <tr> <th colspan="2">Axis: ancestor-or-self </th> </tr> <tr> <th>Element</th> <th>Node-set</th> </tr> <tr> <td>AAA id = a1</td> <td>sourcea1</td> </tr> <tr> <td>BBB id = b1</td> <td>sourcea1b1</td> </tr> <tr> <td>BBB id = b2</td> <td>sourcea1b2</td> </tr> <tr> <td>AAA id = a2</td> <td>sourcea2</td> </tr> <tr> <td>BBB id = b3</td> <td>sourcea2b3</td> </tr> <tr> <td>BBB id = b4</td> <td>sourcea2b4</td> </tr> <tr> <td>CCC id = c1</td> <td>sourcea2c1</td> </tr> <tr> <td>CCC id = c2</td> <td>sourcea2c1c2</td> </tr> <tr> <td>BBB id = b5</td> <td>sourcea2b5</td> </tr> <tr> <td>CCC id = c3</td> <td>sourcea2b5c3</td> </tr> </table> HTML view
|
XSLT stylesheet
<xsl:stylesheet version = '1.0'
xmlns:xsl='http://www.w3.org/1999/XSL/Transform'> <xsl:template match="/"> <table border="1" cellpadding="6"> <tr> <th colspan="2">Axis: ancestor-or-self </th> </tr> <tr> <th>Element</th> <th>Node-set</th> </tr> <xsl:for-each select="/source//*"> <xsl:call-template name="print"/> </xsl:for-each> </table> </xsl:template> <xsl:template name="print"> <tr> <td> <xsl:value-of select="name()"/> <xsl:text> id = </xsl:text> <xsl:value-of select="./@id"/> </td> <td> <xsl:for-each select="ancestor-or-self ::*"> <xsl:if test="not(@id)"> <xsl:value-of select="name()"/> </xsl:if> <xsl:value-of select="./@id"/> <xsl:text/> </xsl:for-each> </td> </tr> </xsl:template> </xsl:stylesheet> |