Share via


Resource: test.xml and test.xsl (XSLT.js Example)

 

This project uses two resource files, an XML data file and an XSLT style sheet. For the XML file, use test.xml from the LoadXMLFile project. The XSLT style sheet, test.xsl, is listing in this topic. This style sheet renames specified elements and leaves others unchanged.

XML Data File (test.xml)

<?xml version="1.0"?>
<root>
   <node>one</node>
   <nodes>
      <node>1</node>
      <node>2</node>
   </nodes>
   <node>two</node>
</root>

XSLT Style Sheet (test.xsl)

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
           version="1.0">

  <!-- Map "root" element to "network" element. -->
  <xsl:template match="root">
    <xsl:element name="network">
       <xsl:apply-templates/>
    </xsl:element>   
  </xsl:template>

  <!-- Keep any other elements as-is. -->
  <xsl:template match="/ | @* | node()">
    <xsl:copy>
      <xsl:apply-templates select="@* | node()"/>
    </xsl:copy>
  </xsl:template>

</xsl:stylesheet>

To add test.xml and test.xsl to the XSLT Project

  1. Copy test.xml from above, and paste it into a text file. Save the file as test.xml to the XSLTProj folder

  2. Copy the XSLT file above, and paste it into a text file. Save the file as test.xsl to the XSLTProj folder.

Next, run the project. The result should be the output shown in the following topic.