Altova Mailing List Archives>Archive Index >microsoft.public.xsl Archive Home >Recent entries [Thread Prev] >Thread Next - Re: using xslt axes using xslt axesTo: NULL Date: 5/28/2009 5:18:00 AM Hi,
I have an xml file and I am trying to get some text output from the
xml data using xslt transformation. (using .Net classes.).
I am using the preceding/following axes of the xslt to get the desired
output. Requirement is to ignore the xml nodes which have one
attribute's value repeated in the subsequent nodes ("main/root/test/
new/@key" attribute value in below example.).
The problem is that the preceding and following axes of xslt searches
in all the nodes instead of searching only in the child nodes of the
current node.
The current and expected output is as shown below:
<b>xml:</b>
<main>
<root>
<test name="1">
<new key="4" />
<new key="1" />
<new key="3" />
<new key="1" />
</test>
<test name="2">
<new key="50"/>
<new key="10"/>
<new key="1" />
<new key="60"/>
<new key="70"/>
<new key="70"/>
</test>
<test name="3">
<new key="8" />
<new key="1" />
<new key="3" />
<new key="9" />
<new key="7" />
<new key="7" />
</test>
</root>
</main>
<b>xslt:</b>
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/
Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-
prefixes="msxsl">
<xsl:output method="text" />
<xsl:template match="main" xml:space="preserve">
<xsl:for-each select="root/test">
<xsl:for-each select=" *[not(preceding::*/@key =
@key) ]">
//<xsl:value-of select="@key"/>
</xsl:for-each>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
<b>Current output:</b>
//4
//1
//3
//50
//10
//60
//70
//8
//9
//7
<b>Expected output:</b>
//4
//1
//3
//50
//10
//1
//60
//70
//8
//1
//3
//9
//7
The C# code which i am using for transformation is:
XslCompiledTransform transformer = new XslCompiledTransform();
transformer.Load(@"C:\test.xslt");
transformer.Transform(@"C:\XMLFile1.xml", @"C:
\Class1.cs"(OUTPUT_FILE));
Can anyone tell if this is the expected behaviour of 'preceding' axes.
And how to get the expected output. (using xslt 1.0)
Thanks in advance.
Manish Gupta
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
