Copy.xml
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="copy.xsl"?>
<root>
<cinema id="1">
<film>Predestination</film>
<director>Spierig Brothers</director>
<year>2014</year>
</cinema>
<cinema id="2">
<film>Inception</film>
<director>Christopher Nolan</director>
<year>2010</year>
</cinema>
</root>
The template is defined to match all attributes and elements using “@*|*”. It is applied to the “cinema” node and value of attribute “id” and name of the film, “film” is written in output document.
Copy.xsl
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="@*|*">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="cinema">
<xsl:copy>
<xsl:value-of select="@id"/>
<xsl:text> </xsl:text>
<xsl:value-of select="film"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
The generated output document gives below information:
<?xml version="1.0"?>
<cinema>1 Predestination</cinema>
<cinema>2 Inception</cinema>
Comments
No comments have been made yet.
Please login to leave a comment. Login now