xsl-list
[Top] [All Lists]

RE: [xsl] Sorting Problem with Xml and Xsl

2007-03-12 14:07:15
Thanks for the quick response. Please note that I am a newbie to xsl and just trying to get a feel of it. But, with the solution you posted, it sorts with in the worksheet nodes only. I want to sort all the <s:Data s:Type="String"></s:Data> elements text with in all the worksheets, so for example
my input file
-------------------
<?xml version='1.0'?>
<?mso-application progid='Excel.Sheet'?>
<s:Workbook xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:s="urn:schemas-microsoft-com:office:spreadsheet">
 <s:Worksheet s:Name="Sample1">
   <s:Table>
     <s:Row>
       <s:Cell>
         <s:Data s:Type="String">RJTGOVBVHX</s:Data>
       </s:Cell>
     </s:Row>
     <s:Row>
       <s:Cell>
         <s:Data s:Type="String">IEXGTQYSBQ</s:Data>
       </s:Cell>
     </s:Row>
   </s:Table>
 </s:Worksheet>
 <s:Worksheet s:Name="Sample2">
   <s:Table>
     <s:Row>
       <s:Cell>
         <s:Data s:Type="String">WUGRDFHDTV</s:Data>
       </s:Cell>
     </s:Row>
     <s:Row>
       <s:Cell>
         <s:Data s:Type="String">PQFWLWQYQW</s:Data>
       </s:Cell>
     </s:Row>
   </s:Table>
 </s:Worksheet>
</s:Workbook>

the output that I want to show is
--------------------------------------------
<?xml version='1.0'?>
<?mso-application progid='Excel.Sheet'?>
<s:Workbook xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:s="urn:schemas-microsoft-com:office:spreadsheet">
 <s:Worksheet s:Name="Sample1">
   <s:Table>
     <s:Row>
       <s:Cell>
         <s:Data s:Type="String">IEXGTQYSBQ</s:Data>
       </s:Cell>
     </s:Row>
     <s:Row>
       <s:Cell>
         <s:Data s:Type="String">PQFWLWQYQW</s:Data>
       </s:Cell>
     </s:Row>
   </s:Table>
 </s:Worksheet>
 <s:Worksheet s:Name="Sample2">
   <s:Table>
     <s:Row>
       <s:Cell>
         <s:Data s:Type="String">RJTGOVBVHX</s:Data>
       </s:Cell>
     </s:Row>
     <s:Row>
       <s:Cell>
         <s:Data s:Type="String">WUGRDFHDTV</s:Data>
       </s:Cell>
     </s:Row>
   </s:Table>
 </s:Worksheet>
</s:Workbook>


Thanks
Ram


From: cknell(_at_)onebox(_dot_)com
Reply-To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: RE: [xsl] Sorting Problem with Xml and Xsl
Date: Mon, 12 Mar 2007 16:25:12 -0400

Your stylesheet doesn't match your input document. You left out several layers of nested elements.

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
  xmlns:s="urn:schemas-microsoft-com:office:spreadsheet"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
  <xsl:strip-space elements="*" />
  <xsl:output method="xml" indent="yes" encoding="UTF-16" />

    <xsl:template match="/">
        <xsl:apply-templates />
    </xsl:template>

    <xsl:template match="s:Workbook">
      <s:Workbook xmlns:x="urn:schemas-microsoft-com:office:excel"
          xmlns:o="urn:schemas-microsoft-com:office:office"
          xmlns:s="urn:schemas-microsoft-com:office:spreadsheet">
        <xsl:apply-templates />
      </s:Workbook>
    </xsl:template>

    <xsl:template match="s:Worksheet">
      <s:Worksheet>
        <xsl:apply-templates />
      </s:Worksheet>
    </xsl:template>

    <xsl:template match="s:Table">
      <s:Table>
        <xsl:for-each select="s:Row">
          <xsl:sort select="s:Cell/s:Data" />
          <xsl:copy-of select="." />
        </xsl:for-each>
      </s:Table>
    </xsl:template>

</xsl:stylesheet>
--
Charles Knell
cknell(_at_)onebox(_dot_)com - email



-----Original Message-----
From:     Ram Shan <hellodck(_at_)hotmail(_dot_)com>
Sent:     Mon, 12 Mar 2007 13:27:04 -0600
To:       xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject:  [xsl] Sorting Problem with Xml and Xsl

I can not get this sorting to work. any help is greatly appreciated. I am
using MSXml parser and c# to transform. Thanks
Here is Sample XML
-------------
<?xml-stylesheet  type="text/xsl" href="rowextrated2.xsl" ?>
<?mso-application progid='Excel.Sheet'?>
<s:Workbook xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:s="urn:schemas-microsoft-com:office:spreadsheet">
  <s:Worksheet s:Name="Sample1">
    <s:Table>
      <s:Row>
        <s:Cell>
          <s:Data s:Type="String">Maa</s:Data>
        </s:Cell>
      </s:Row>
      <s:Row>
        <s:Cell>
          <s:Data s:Type="String">Baa</s:Data>
        </s:Cell>
      </s:Row>
      <s:Row>
        <s:Cell>
          <s:Data s:Type="String">Aaa</s:Data>
        </s:Cell>
      </s:Row>
    </s:Table>
  </s:Worksheet>
  <s:Worksheet s:Name="Sample2">
    <s:Table>
      <s:Row>
        <s:Cell>
          <s:Data s:Type="String">Caa</s:Data>
        </s:Cell>
      </s:Row>
      <s:Row>
        <s:Cell>
          <s:Data s:Type="String">Qaa</s:Data>
        </s:Cell>
      </s:Row>
      <s:Row>
        <s:Cell>
          <s:Data s:Type="String">Zaa</s:Data>
        </s:Cell>
      </s:Row>
    </s:Table>
  </s:Worksheet>
</s:Workbook>


--------------My Xsl looks like this. But the problem is it does not take
get me the sorted out . please check below
<?xml version="1.0" encoding="utf-8" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
xmlns:s="urn:schemas-microsoft-com:office:spreadsheet" version="1.0">
  <xsl:output method="xml" indent="yes" encoding="utf-16"/>
  <xsl:template match="s:Workbook">
    <xsl:copy>
      <xsl:apply-templates>
        <xsl:sort data-type="text" select="s:Cell/s:Data"
case-order="lower-first" />
      </xsl:apply-templates>
    </xsl:copy>
  </xsl:template>

  <xsl:template match="*">
    <xsl:copy>
      <xsl:apply-templates/>
    </xsl:copy>
  </xsl:template>
</xsl:stylesheet>


---Desired output


<?xml-stylesheet  type="text/xsl" href="rowextrated2.xsl" ?>
<?mso-application progid='Excel.Sheet'?>
<s:Workbook xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:s="urn:schemas-microsoft-com:office:spreadsheet">
  <s:Worksheet s:Name="Sample1">
    <s:Table>
      <s:Row>
        <s:Cell>
          <s:Data s:Type="String">Aaa</s:Data>
        </s:Cell>
      </s:Row>
      <s:Row>
        <s:Cell>
          <s:Data s:Type="String">Baa</s:Data>
        </s:Cell>
      </s:Row>
      <s:Row>
        <s:Cell>
          <s:Data s:Type="String">Caa</s:Data>
        </s:Cell>
      </s:Row>
    </s:Table>
  </s:Worksheet>
  <s:Worksheet s:Name="Sample2">
    <s:Table>
      <s:Row>
        <s:Cell>
          <s:Data s:Type="String">Maa</s:Data>
        </s:Cell>
      </s:Row>
      <s:Row>
        <s:Cell>
          <s:Data s:Type="String">Qaa</s:Data>
        </s:Cell>
      </s:Row>
      <s:Row>
        <s:Cell>
          <s:Data s:Type="String">Zaa</s:Data>
        </s:Cell>
      </s:Row>
    </s:Table>
  </s:Worksheet>
</s:Workbook>

_________________________________________________________________
Play Flexicon: the crossword game that feeds your brain. PLAY now for FREE. 
  http://zone.msn.com/en/flexicon/default.htm?icid=flexicon_hmtagline


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--




--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--


_________________________________________________________________
Find a local pizza place, movie theater, and more?.then map the best route! http://maps.live.com/?icid=hmtag1&FORM=MGAC01


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--