How to work with XPathNodeIterator?

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:eek: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>
 
H

Hvid Hat

Hello Hvid,
<xsl:template match="Documents">
<xsl:value-of select="user:buildCountryList(msxsl:node-set(.))"/>
</xsl:template>
</xsl:stylesheet>

Should have been persons instead of documents:

<xsl:template match="Persons">
<xsl:value-of select="user:buildCountryList(msxsl:node-set(.))"/>
</xsl:template>
</xsl:stylesheet
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top