Friday, December 21, 2012

an XSLT example

This suggests that one apply an XSLT (another thing I learned about from C# 4.0 in a Nutshell) transformation like so:

XPathDocument myXPathDoc = new XPathDocument(myXmlPath);
XslTransform myXslTrans = new XslTransform();
myXslTrans.Load(myXsltPath);
XmlTextWriter myWriter = new XmlTextWriter("result.html",null);
myXslTrans.Transform(myXPathDoc,null,myWriter);

 
 

This is something else I found which has this XML...

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<?xml-stylesheet type="text/xsl" href="tutorials.xsl"?>
<tutorials>
   <tutorial>
      <name>XML Tutorial</name>
      <url>http://www.quackit.com/xml/tutorial</url>
   </tutorial>
   <tutorial>
      <name>HTML Tutorial</name>
      <url>http://www.quackit.com/html/tutorial</url>
   </tutorial>
</tutorials>

 
 

...and suggests that it may be used with this:

<xsl:template match="tutorial">
   <span class="tutorial-name"><xsl:value-of select="name"/></span>
   <span class="tutorial-url"><xsl:value-of select="url"/></span>
</xsl:template>

No comments:

Post a Comment