T
Tony
Hello!
Here is the C# code that tranform the xml file into html.
Below is both the Xml file and the xslt file.
I just wonder if somebody could show me with a simple example how to use the
anchestor with my Xml file.
protected void Page_Load(object sender, EventArgs e)
{
XslCompiledTransform xslt = new XslCompiledTransform();
xslt.Load(@"C:\Users\Tony\programmering\Websites\slask5\personData.xsl");
// Execute the transform and output the results to a file
xslt.Transform(@"C:\Users\Tony\programmering\Websites\slask5\personData.xml",
@"C:\Users\Tony\programmering\Websites\slask5\personData.html");
}
Here is the Xml file
<?xml version="1.0" ?>
<?xml-stylesheet type="text/xsl" href="book.xsl"?>
<Books>
<Book>
<Chapter number="1">This is the first chapter</Chapter>
<Chapter number="2">This is the second chapter</Chapter>
<Chapter number="3">This is the third chapter</Chapter>
<Chapter number="4">This is the fourth chapter</Chapter>
<Chapter number="5">This is the fifth chapter</Chapter>
</Book>
</Books>
Here is the xslt file
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<head>
<title>This shows the context position and context size</title>
</head>
<body>
<h3>Context position and context size demo.</h3>
<xsl:apply-templates select="Books/Book/Chapter" />
</body>
</html>
</xsl:template>
<xsl:template match="Chapter">
<xsl:if test="position()=2">
<p>When the context node is the second <b>Chapter</b> element node
then </p>
<p>the context position is <xsl:value-of select="position()" /></p>
<p>and the context size is <xsl:value-of select="last()" /></p>
<p>The text the <b>Chapter</b> element node contain is <xsl:value-of
select="." /></p>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
//Tony
Here is the C# code that tranform the xml file into html.
Below is both the Xml file and the xslt file.
I just wonder if somebody could show me with a simple example how to use the
anchestor with my Xml file.
protected void Page_Load(object sender, EventArgs e)
{
XslCompiledTransform xslt = new XslCompiledTransform();
xslt.Load(@"C:\Users\Tony\programmering\Websites\slask5\personData.xsl");
// Execute the transform and output the results to a file
xslt.Transform(@"C:\Users\Tony\programmering\Websites\slask5\personData.xml",
@"C:\Users\Tony\programmering\Websites\slask5\personData.html");
}
Here is the Xml file
<?xml version="1.0" ?>
<?xml-stylesheet type="text/xsl" href="book.xsl"?>
<Books>
<Book>
<Chapter number="1">This is the first chapter</Chapter>
<Chapter number="2">This is the second chapter</Chapter>
<Chapter number="3">This is the third chapter</Chapter>
<Chapter number="4">This is the fourth chapter</Chapter>
<Chapter number="5">This is the fifth chapter</Chapter>
</Book>
</Books>
Here is the xslt file
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<head>
<title>This shows the context position and context size</title>
</head>
<body>
<h3>Context position and context size demo.</h3>
<xsl:apply-templates select="Books/Book/Chapter" />
</body>
</html>
</xsl:template>
<xsl:template match="Chapter">
<xsl:if test="position()=2">
<p>When the context node is the second <b>Chapter</b> element node
then </p>
<p>the context position is <xsl:value-of select="position()" /></p>
<p>and the context size is <xsl:value-of select="last()" /></p>
<p>The text the <b>Chapter</b> element node contain is <xsl:value-of
select="." /></p>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
//Tony