How to work with XPathNodeIterator?

Discussion in 'XML' started by Hvid Hat, Mar 5, 2008.

  1. Hvid Hat

    Hvid Hat Guest

    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>
     
    Hvid Hat, Mar 5, 2008
    #1
    1. Advertising

  2. Hvid Hat

    Hvid Hat Guest

    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
     
    Hvid Hat, Mar 5, 2008
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. tina-e
    Replies:
    0
    Views:
    337
    tina-e
    Apr 30, 2004
  2. Raed Sawalha

    Binding XPathNodeIterator to Repeater

    Raed Sawalha, Sep 29, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    633
    Raed Sawalha
    Sep 29, 2004
  3. craig dicker
    Replies:
    9
    Views:
    680
    Juan T. Llibre
    Jul 7, 2005
  4. =?Utf-8?B?RGF2aWQ=?=

    XPathNodeIterator reading embedded tags

    =?Utf-8?B?RGF2aWQ=?=, Aug 3, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    417
    =?Utf-8?B?RGF2aWQ=?=
    Aug 3, 2005
  5. TB
    Replies:
    2
    Views:
    3,740
Loading...

Share This Page