xsl-list
[Top] [All Lists]

Query regarding usage of <xsl:sort> in MSXML

2002-10-15 20:51:35
Hello all,

I am using MSXML4.0. Have a query regarding usage of <xsl:sort> in MSXML
VC++ MFC.

Lets say the hirearchy of my xml dom document is like this:

<Media>
  <Patient name=pat1name id=pat1id>
        <Study uid=st1.1.uid comments="study1">
        </Study>

        <Study uid=st1.2.uid comments="study2">
        </Study>
  </Patient>

<Patient name=pat2name id=pat2id>
        <Study uid=st2.1.uid comments="study1">
        </Study>

        <Study uid=st2.2.uid comments="study2">
        </Study>
</Patient>
</Media>


And I have a Stylesheet for this XML like this:

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
<xsl:template match="Media">

<xsl:apply-templates select="Patient">
<xsl:sort select="name" data-type="text" order="descending"/>
</xsl:apply-templates>

</xsl:template>

<xsl:template match="Patient">
<xsl:value-of select="@name"/><br/>
</xsl:template>

</xsl:stylesheet>

I want to get the name attribute of all Patients with the order of name
in "descending" order.

I need to do the name using MSXML VC++ MFC. (msxml4.dll is added to the
MFC using ole automation)

{
        ............................. // Dom Document loaded and
dispatch available
        LPDISPpaCH lpDisp = myDOMDoc.getElementsByTagName("Media");
        IXMLDOMNode aMediaNode(lpDisp);

        // Get all the Patient Nodes under Media
        lpDisp = aMediaNode.selectNodes("Patient");
        IXMLDOMNodeList aPatNodesList(lpDisp);

        // Walk through the PatNodesList and get the Attributes
        // reset the iterator of the list
        aPatNodesList.reset();  
        for (int i=0; i < aPatNodesList.GetLength(); ++i)       
        {
              lpDisp = aPatNodesList.GetItem(i);
                  IXMLDOMNode aPatNode(lpDisp);

              // Get the attributes
             lpDisp = aPatNode.GetAttributes();

            // Attributes come in a NodeMap, from that get the name
attribute
            IXMLDOMNamedNodeMap aPatAttributes(lpDisp);

           // name is the 0th attribute (first item)
              lpDisp = aPatAttributes.GetItem(0);
          IXMLDOMNode aAtt(lpDisp);
         
        COleVariant aVal(aAtt.GetNodeValue());
        CString aAttValue(aVal.bstrVal);
          AfxMessageBox(aAttValue);       
         } // for all the Patient Nodes under Media

QUERY:
        
        Here, I want to get all the Patient nodes in the order of name
in descending.
        i.e. like pat2name, pat1name instead of pat1name, pat2name.

        I understand that there is an API for doing a transformNode
where we can mention the stylesheet/string to do the same.
        But I am not able to findout where it has to be done, how to
combine the selectNodes with this functionality.
        Can you tell me how to fitin that sorting functionlaity in the
above code?

        Can any one of you help me in this regard?


Thanks in advance,
Nirmala



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list



<Prev in Thread] Current Thread [Next in Thread>