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 | 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 August 6th, 2008, 01:35 AM
Authorized User
 
Join Date: Jul 2008
Location: , , .
Posts: 53
Thanks: 0
Thanked 0 Times in 0 Posts
Default XSL help

XSLT: Version 1.0
Processor: Xalan-C_1_8_0-windows_2000-msvc_60 /xerces-c_2_5_0-windows_nt-msvc_60
Platform: Windows XP

Please note i have not posted any xml or xsl or output here.

Its possible to define the xsl as below algorithm

[u]Initialising: </u>$periods = null; $pp=null; $cc=null; $other=null
[u]In XSL i can able to write it as ?</u>
<xsl:variable name="periods" select="null"/>
<xsl:variable name="pp" select="null"/>
<xsl:variable name="cc" select="null"/>
<xsl:variable name="other" select="null"/>


[u]Algorithm:</u>
     if $cc is null and $creditPeriods.hasNext() then $cc = nextConsecutivePeriod ($creditPeriods)
     //
     if $pp is null and $pastPeriods.hasNext() then $pp = nextConsecutivePeriod ($pastPeriods)
     // If $cc and $pp exist, merge them
     if $pp is not null and $cc is not null then
         ($pp, $cc, $other) = mergePeriods ($pp, $cc)
         if $other is not null then $periods.add ($other)
     // If only $pp, add directly to periods
     else if $pp is not null then
         $periods.add($pp)
         $pp = null
     // If only $cc, add to $periods
     else if $cc is not null then
         $periods.add($cc)
         $cc = null
     // Otherwise, nothing left then end
     else
         break
     fi
end while
// Add advanced charge periods
while $advancedPeriods.hasNext()
     $aa = nextConsecutivePeriod($advancedPeriods)
    $periods.add(aa)

[u]In XSL i can able to write it as ?</u>

<xsl:if test="$cc='null' and $pastPeriods.hasNext()">
</xsl:if>
I dont know how to handle $pastPeriods.hasNext() in XSL. Since i am using the xalan extension function which the pastPeriods is an xsl variable contains the xml tree structure such as

<AccessFeesGroupList>
     <AccessFeesGroup>
         <Period dateFrom='<>' dateTo='<>' discountValue='<>' invoiceLineValue='<>' vatValue='<>' />"
     </AccessFeesGroup>
</AccessFeesGroupList>

Please ignote that i have not posted the input xml and the expected output.
Reply With Quote
  #2 (permalink)  
Old August 6th, 2008, 02:42 AM
samjudson's Avatar
Friend of Wrox
Points: 8,687, Level: 40
Points: 8,687, Level: 40 Points: 8,687, Level: 40 Points: 8,687, Level: 40
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2007
Location: Newcastle, , United Kingdom.
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

You've been posting to this forum long enough now you should really know the answer to this one yourself (in fact I suspect you do).

You cannot write code in XSLT in the way you are hoping for - variables cannot be updated once they have been created (i.e. $x = $x + 1 is invalid).

Rahter than post psuedo-code for what you want to do why not try (do we have to mention this again!) posting your input XML, and what you want your output XML to look like, and what you have tried so far and we MAY be able to help you.

/- Sam Judson : Wrox Technical Editor -/
Reply With Quote
  #3 (permalink)  
Old August 6th, 2008, 03:03 AM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

It's very hard to reverse-engineer from a procedural algorithm that solves a problem to a declarative description of the problem, and I would really advise against trying to work that way. Please describe the problem, not your procedural approach to solving it.

Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer's Reference
Reply With Quote
  #4 (permalink)  
Old August 8th, 2008, 01:15 AM
Authorized User
 
Join Date: Jul 2008
Location: , , .
Posts: 53
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Yes I agreed.

I need to find the label from Input.xml by mapping the RateplanUsageList/RateplanUsage/tm=$RateplanId

1) If my $RateplanId is 'TEST' which is not in the Input.xml file, the output is 'Gebruikskosten buiten bundel' is correct as expected
2) If my $RateplanId is 'TZAOP',
    Actual output: Gebruikskosten buiten bundel ( Is not as expected )
    Expected output: Gebruikskosten


[u]File.xsl</u>

<xsl:apply-templates select="document($root/Envelope/Part/@File)/Configuration/RateplanUsageList" mode="Discount_label">
    <xsl:with-param name="RateplanId"><xsl:value-of select="AggSet/Att[@Ty='TM']/@Id"/></xsl:with-param>
</xsl:apply-templates>

<xsl:template match="/Configuration/RateplanUsageList" mode="Discount_label"> <xsl:param name="RateplanId"/>
     <xsl:choose>
         <xsl:when test="RateplanUsage/tm=$RateplanId">
         <xsl:value-of select="RateplanUsage[@Id=???]/@label"/>
         </xsl:when>
         <xsl:otherwise>
             <xsl:value-of select="RateplanUsage[@id='0']/@label"/> otherwise
         </xsl:otherwise>
     </xsl:choose>
</xsl:template>



[u]Input.xml</u>

<RateplanUsageList>
    <RateplanUsage id="0" label="Gebruikskosten buiten bundel" discountLabel="Korting gebruikskosten">
    
    </RateplanUsage>
    <RateplanUsage id="1" label="Gebruikskosten" discountLabel="Korting gebruikskosten">
     <tm>TZAOP</tm>
     <tm>AOP</tm>
    </RateplanUsage>
</RateplanUsageList>
Reply With Quote
  #5 (permalink)  
Old August 8th, 2008, 03:00 AM
samjudson's Avatar
Friend of Wrox
Points: 8,687, Level: 40
Points: 8,687, Level: 40 Points: 8,687, Level: 40 Points: 8,687, Level: 40
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2007
Location: Newcastle, , United Kingdom.
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

<xsl:value-of select="RateplanUsage[tm=$RateplanId]/@label"/>

You really should get a good XSLT book - it would probably be quicker in the long run as you appear to be doing quite a lot of work with XSLT and needing to ask a lot of questions.

/- Sam Judson : Wrox Technical Editor -/
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
xsl:param and xsl:apply-templates' "select" newbieboobers XSLT 1 March 25th, 2008 07:23 PM
Pass link values as xsl:parameter to php5 then xsl pauljr8 XSLT 1 July 2nd, 2007 10:32 PM
differnce between xsl:apply-templates and xsl:call chandu.mca007 XSLT 2 June 12th, 2007 04:12 AM
xsl advise needed - Replacing UID through XSL Billyl XSLT 6 February 28th, 2006 05:46 AM
XSL Transform with xsl string NOT xsl file skin XSLT 0 June 16th, 2003 07:30 AM



All times are GMT -4. The time now is 08:54 AM.


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