Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old July 10th, 2007, 12:53 PM
Authorized User
 
Join Date: Jul 2007
Location: , , .
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default sorting

Hi,

Can anyone please help me?

I have the xml file:

<Issue>
     <IssueHistory_CreationDate>2004-01-01</IssueHistory_CreationDate>
      <Status>
           <Name>Find</Name>
                <Amount>28</Amount>
           <Name>resolved</Name>
                <Amount>0</Amount>
            <Name>Finished</Name>
                <Amount>0</Amount>
   </Status>
    <IssueHistory_CreationDate>2004-01-02</IssueHistory_CreationDate>
    <Status>
           <Name>Find</Name>
               <Amount>6</Amount>
          <Name>Resolved</Name>
                <Amount>6</Amount>
           <Name>Finished</Name>
                <Amount>4</Amount>
   </Status>

But I want to sort the Fined, Resolved and Finished amount
with xslt.

I want that the xslt file generate my xml file to this:

<string>Fined</string>
<Number>28</Number>
<Number>6</Number>

<string>solved</string>
<Number>0</Number>
<Number>6</Number>

<string>Finished</string>
<Number>0</Number>
<Number>4</Number>

Does anyone know how I can do this?

Reply With Quote
  #2 (permalink)  
Old July 10th, 2007, 01:21 PM
mhkay's Avatar
Wrox Author
Points: 18,481, Level: 59
Points: 18,481, Level: 59 Points: 18,481, Level: 59 Points: 18,481, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,960
Thanks: 0
Thanked 292 Times in 287 Posts
Default

If the set of status values is fixed, just do

<xsl:template name="statusReport">
  <xsl:param name="status"/>
  <string><xsl:value-of select="$status"/></string>
  <xsl:for-each select="IssueHistory/Status[Name=$status]">
    <Number><xsl:value-of select="Amount"/></Number>
  </
</

<xsl:template match="Issue">
  <xsl:call-template name="statusReport">
    <xsl:with-param name="status">Find</xsl:with-param>
  </xsl:call-template>
  <xsl:call-template name="statusReport">
    <xsl:with-param name="status">Resolved</xsl:with-param>
  </xsl:call-template>

etc.

If the set of status values isn't fixed, then you have a grouping problem (or you could tackle it as a grouping problem anyway) - use xsl:for-each-group in XSLT 2.0, or see www.jenitennison.com/xslt/grouping

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Reply With Quote
  #3 (permalink)  
Old July 10th, 2007, 01:48 PM
Authorized User
 
Join Date: Jul 2007
Location: , , .
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Mhkay,

what do mean with If the set of status values isn't fixed?

I want to show al the 3, Fined, Solved and Finished. The file must show the Fined, Solved and Finished with grouping their amount.



Reply With Quote
  #4 (permalink)  
Old July 10th, 2007, 02:51 PM
mhkay's Avatar
Wrox Author
Points: 18,481, Level: 59
Points: 18,481, Level: 59 Points: 18,481, Level: 59 Points: 18,481, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,960
Thanks: 0
Thanked 292 Times in 287 Posts
Default

If your input documents always use "Fined" "Solved" and "Finished" then that's what I call a fixed set of values. If different documents might use different values, for example "Complete" and "Postponed" then you need to use grouping techniques.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Reply With Quote
  #5 (permalink)  
Old July 10th, 2007, 03:17 PM
Authorized User
 
Join Date: Jul 2007
Location: , , .
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi again,

okee, thanks. But wich of the two should I use?

<xsl:template name="statusReport">
  <xsl:param name="status"/>
  <string><xsl:value-of select="$status"/></string>
  <xsl:for-each select="IssueHistory/Status[Name=$status]">
    <Number><xsl:value-of select="Amount"/></Number>
  </
</

<xsl:template match="Issue">
  <xsl:call-template name="statusReport">
    <xsl:with-param name="status">Find</xsl:with-param>
  </xsl:call-template>
  <xsl:call-template name="statusReport">
    <xsl:with-param name="status">Resolved</xsl:with-param>
  </xsl:call-template>


Reply With Quote
  #6 (permalink)  
Old July 10th, 2007, 03:23 PM
mhkay's Avatar
Wrox Author
Points: 18,481, Level: 59
Points: 18,481, Level: 59 Points: 18,481, Level: 59 Points: 18,481, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,960
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Eh?

I gave you two templates one of which calls the other. If you can't work out how to integrate those into a stylesheet, then you need to do some more basic reading before you do any more coding.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Reply With Quote
  #7 (permalink)  
Old July 10th, 2007, 03:49 PM
Authorized User
 
Join Date: Jul 2007
Location: , , .
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi again,

Yes, I am busy with basic reading.

first of all thank you for your help.

I have this:

<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" indent="yes"/>

<xsl:template name="statusReport">
<xsl:param name="status"/>
<string><xsl:value-of select="$status"/></string>
<xsl:for-each select="IssueHistory/Status[Name=$status]">
<Number><xsl:value-of select="Amount"/></Number>

 <row >
        <xsl:for-each select="Issue/IssueHistory_CreationDate">
         <String><xsl:apply-templates/></String>
        </xsl:for-each>
   </row>

<xsl:template match="Issue">
<xsl:call-template name="statusReport">
<xsl:with-param name="status">Find</xsl:with-param>
</xsl:call-template>

<xsl:call-template name="statusReport">
<xsl:with-param name="status">Resolved</xsl:with-param>
</xsl:call-template>

</xsl:template>
</xsl:stylesheet>

Is this the correct xslt?

Reply With Quote
  #8 (permalink)  
Old July 10th, 2007, 04:04 PM
mhkay's Avatar
Wrox Author
Points: 18,481, Level: 59
Points: 18,481, Level: 59 Points: 18,481, Level: 59 Points: 18,481, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,960
Thanks: 0
Thanked 292 Times in 287 Posts
Default

You need to add the missing end tags to make it well-formed. I used </ as a short-hand because that's what I use in an XML editor, and I assume people can fill in the gaps.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Reply With Quote
  #9 (permalink)  
Old July 11th, 2007, 02:52 AM
Authorized User
 
Join Date: Jul 2007
Location: , , .
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" indent="yes"/>

<xsl:template name="statusReport">
<xsl:param name="status"/><string><xsl:value-of select="$status"/></string>

<xsl:for-each select="Issue/Status[Name=$status]"><Number><xsl:value-of select="Amount"/></Number>
</xsl:for-each>
<xsl:template match="Issue"></xsl:template>

<Chart_data>

 <row >
        <xsl:for-each select="Issue/IssueHistory_CreationDate">
         <String><xsl:apply-templates/></String>
        </xsl:for-each>
   </row>

<row>
<xsl:call-template name="statusReport">
<xsl:with-param name="status">Find</xsl:with-param>
</xsl:call-template>
</row>

<row>
<xsl:call-template name="statusReport">
<xsl:with-param name="status">Resolved</xsl:with-param>
</xsl:call-template>
</row>

</Chart_data>
</xsl:template>
</xsl:stylesheet>

When I translate this withe the xml file i got a error. It says:
Invalid at the top level of the document. Error processing resource 'file:///C:/Documents and Settings/Desktop/resu...
Reply With Quote
  #10 (permalink)  
Old July 11th, 2007, 05:46 AM
mhkay's Avatar
Wrox Author
Points: 18,481, Level: 59
Points: 18,481, Level: 59 Points: 18,481, Level: 59 Points: 18,481, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,960
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Try closing the first template before you open the second one.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
SORTING pallone XSLT 3 October 29th, 2006 08:45 AM
Sorting sunny76 Excel VBA 2 September 19th, 2005 09:31 PM
Datagrid sorting by non alphabetical sorting? LLAndy VS.NET 2002/2003 1 July 15th, 2004 01:20 AM
Sorting? pbernardo XSLT 2 October 27th, 2003 11:34 AM
Need help Sorting athanatos XSLT 5 August 11th, 2003 07:51 PM



All times are GMT -4. The time now is 09:35 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.