Wrox Programmer Forums
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 11th, 2007, 06:05 AM
Authorized User
 
Join Date: Jul 2007
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

But I have done this.

You see that I have close the templates with:
</xsl:call-template>

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

 
Old July 11th, 2007, 06:11 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

It's not xsl:call-template that's the issue, it's xsl:template.

I'm afraid this is getting a bit childish. You'll be asking me where the shift key on your keyboard is next.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old July 11th, 2007, 07:32 AM
Authorized User
 
Join Date: Jul 2007
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Sorry I am a new one in XSL. and if i know how i can fix something like this than i would not come in this forum and ask for questions.

mhkay, I have changed somethings in that xsl before, and this is what I get. Is this right? Please help me, it is very important.

<?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 match = "/" >
      <xsl:call-template name="statusReport">
               <xsl:with-param name="status">Gevonden</xsl:with-param>
    </xsl:call-template>
    </xsl:template>
      <xsl:template match = "/">
     <xsl:call-template name="statusReport">
     <xsl:with-param name="status">Opgelost</xsl:with-param>
    </xsl:call-template>
</xsl:template>

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

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


 
Old July 11th, 2007, 07:43 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

You now have two template rules that both say match="/". How can that possibly achieve anything?

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old July 11th, 2007, 07:57 AM
Authorized User
 
Join Date: Jul 2007
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

okee youre right.

This is the new one now.

<?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 match = "/" >
      <xsl:call-template name="statusReport">
               <xsl:with-param name="status">Gevonden</xsl:with-param>
    </xsl:call-template>
     <xsl:call-template name="statusReport">
     <xsl:with-param name="status">Opgelost</xsl:with-param>
    </xsl:call-template>
</xsl:template>

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

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


But how can I ever have this right?

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>

to this xml file
<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>

 
Old July 11th, 2007, 09:38 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Your code now looks more-or-less OK except that the XML says "Fined" where the XSLT says "Opgelost", and you are outputting the <string> element in the wrong place.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old July 12th, 2007, 05:22 AM
Authorized User
 
Join Date: Jul 2007
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi michael,

the code is correct and i get the correct result.

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

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

<xsl:template name="statusReport">
    <xsl:param name="status"></xsl:param>
    <xsl:param name="Amount"></xsl:param>
    <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>
  </xsl:stylesheet>

And this is the result:

<?xml version="1.0" encoding="UTF-8"?>
<string>Fined</string>
<Number>28</Number>
<Number>6</Number>

But How can I retrieve the result of Resolved and Finished?

this is the source 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>

youre xslt file isnt't correct, because I retrieve for the Resolved the same amount as by find.

this is youre xslt:
<xsl:template match = "/" >
      <xsl:call-template name="statusReport">
               <xsl:with-param name="status">Fined</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>

this is the result:
<string>Fined</string>
<Number>28</Number>
<Number>6</Number>
<string>Resolved</string>
<Number>28</Number>
<Number>6</Number>


 
Old July 12th, 2007, 05:41 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

I was misled by the indentation in your source document into thinking it had a different hierarchic structure.

It's not very good XML design to use a sequence such as

<name>
<amount>
<name>
<amout>
<name>
<amount>

It's better to wrap each (name, amount) pair in an enclosing element.

But if you can't change the XML, the answer is to change

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

to

    <xsl:for-each select="Issue/Status/Name[.=$status]">
       <Number><xsl:value-of select="following-sibling::Amount[1]"/></Number>
    </xsl:for-each>

You'll also have to fix the fact that "resolved" is spelt two different ways in your source.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old July 12th, 2007, 06:34 AM
Authorized User
 
Join Date: Jul 2007
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Michael,

wow it's working.(Thanks a lot) Now I can see the amount of Find and Resolved. But how can I see the amount of Finished? I have now the result of Find and Resolved. and want also see the result of Finished.


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>

 
Old July 12th, 2007, 06:44 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

I find your questions quite extraordinary. If you can't extrapolate your current code to handle three cases rather than two, this suggests that you haven't the faintest idea how it works. Even without understanding what the instructions do, it ought to be possible to detect the pattern. Please study the code you have working, alongside an XSLT reference that explains what each instruction does, and try to understand why it works the way it does. Then you should be able to extend it.

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





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





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.