H
Hvid Hat
Hello
I'm really struggling on how to process a part of the document/xml tree in
a C# method in my XSLT (version 1). I've been told to use XPathNodeIterator
but I can't figure out how to work with it, to make it do what I want. I
want to return a string with an unordered list of unique countries. By unique,
I mean that the country may only exist once in the returned list. I can't
use the Muenchian Method for grouping the countries. I must use C# as I'll
add more complex code once I get the basics in place. Anyone, or a better
solution?
XML:
<?xml version="1.0" encoding="UTF-8"?>
<persons>
<person id="1">
<name>John Doe</name>
<country>USA</country>
</person>
<person id="2">
<name>Jane Doe</name>
<country>England</country>
</person>
<person id="3">
<name>Baby Doe</name>
<country>USA</country>
</person>
</persons>
XSLT:
<?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" xmlns:user="urn:my-scripts">
<xsl
utput omit-xml-declaration="yes" encoding="UTF-8"/>
<msxsl:script language="C#" implements-prefix="user"><![CDATA[
public string buildCountryList(XPathNodeIterator pathNodeIterator)
{
string html;
/*
I want to return
<ul>
<li>England</li>
<li>USA</li>
</ul>
*/
return html;
}
]]></msxsl:script>
<xsl:template match="Documents">
<xsl:value-of select="user:buildCountryList(msxsl:node-set(.))"/>
</xsl:template>
</xsl:stylesheet>
I'm really struggling on how to process a part of the document/xml tree in
a C# method in my XSLT (version 1). I've been told to use XPathNodeIterator
but I can't figure out how to work with it, to make it do what I want. I
want to return a string with an unordered list of unique countries. By unique,
I mean that the country may only exist once in the returned list. I can't
use the Muenchian Method for grouping the countries. I must use C# as I'll
add more complex code once I get the basics in place. Anyone, or a better
solution?
XML:
<?xml version="1.0" encoding="UTF-8"?>
<persons>
<person id="1">
<name>John Doe</name>
<country>USA</country>
</person>
<person id="2">
<name>Jane Doe</name>
<country>England</country>
</person>
<person id="3">
<name>Baby Doe</name>
<country>USA</country>
</person>
</persons>
XSLT:
<?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" xmlns:user="urn:my-scripts">
<xsl
<msxsl:script language="C#" implements-prefix="user"><![CDATA[
public string buildCountryList(XPathNodeIterator pathNodeIterator)
{
string html;
/*
I want to return
<ul>
<li>England</li>
<li>USA</li>
</ul>
*/
return html;
}
]]></msxsl:script>
<xsl:template match="Documents">
<xsl:value-of select="user:buildCountryList(msxsl:node-set(.))"/>
</xsl:template>
</xsl:stylesheet>