Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
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 January 29th, 2008, 10:31 AM
Registered User
 
Join Date: Jan 2008
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to fedehf
Default Newbie XSLT question

Hello, I'm new with XSLT and I got assigned to do an xslt spreadsheet at work but I got stuck in this point:
XML:
Code:
  <Intro BillingCycles="12 Billing Cycles"
  FlipDate="None"
  Tier="1">
    Purchase=0.00:F
    BT=0.00:F
    CC=0.00:F
    BillingCycles=12 Billing Cycles
    FlipDate=None
    <Purchase APR="0.00" />
    <BT APR="0.00" />
  </Intro>

  <Intro BillingCycles="12 Billing Cycles"
  FlipDate="None"
  Tier="2">
    Purchase=0.00:F
    BT=0.00:F
    CC=0.00:F
    BillingCycles=12 Billing Cycles
    FlipDate=None
    <Purchase APR="0.00" />
    <BT APR="0.00" />
  </Intro>
  <Intro BillingCycles="12 Billing Cycles"
  FlipDate="None"
  Tier="3">
    Purchase=0.00:F
    BT=0.00:F
    CC=0.00:F
    BillingCycles=12 Billing Cycles
    FlipDate=None
    <Purchase APR="0.00" />
    <BT APR="0.00" />
  </Intro>


<Goto BillingCycles="None"
  FlipDate="None"
  Tier="1">
    Purchase=14.24:V
    BT=14.24:V
    CC=14.24:V
    BillingCycles=None
    FlipDate=None
    <Purchase APR="14.24" />
    <BT APR="14.24" />
  </Goto>

<Goto BillingCycles="None"
  FlipDate="None"
  Tier="2">
    Purchase=14.24:V
    BT=14.24:V
    CC=14.24:V
    BillingCycles=None
    FlipDate=None
    <Purchase APR="14.24" />
    <BT APR="14.24" />
  </Goto>
<Goto BillingCycles="None"
  FlipDate="None"
  Tier="3">
    Purchase=14.24:V
    BT=14.24:V
    CC=14.24:V
    BillingCycles=None
    FlipDate=None
    <Purchase APR="14.24" />
    <BT APR="14.24" />
  </Goto>


I have to select the Intro/@Tier that applies with:
IF<INTRO;PURCHASE;APR> != “None” or is NOT equal to <GOTO;PURCHASE;APR> but from the same Tier.
Example <INTRO[@Tier = 1];PURCHASE;APR> != "None" and <GOTO[@Tier = 1];PURCHASE;APR>

This is what I got so far:
Code:
<xsl:variable name="IntroTiers" select="Intro[@Tier = * and Purchase/@APR!='None' and not(Purchase/@APR != /Goto[@Tier = *]/Purchase/@APR) ]/@Tier" />

This select doesn't work because the second * is selecting "any Tier" and not the same Tier that the first * . I can not think of a way to compare different nodes from the same Tier.
BTW, I can't change the XML, I have to work with that one :(

Sorry for my english.

Thanks


Report this post

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

I'm afraid I don't understand the notation that you are using to express your requirement, that is: IF<INTRO;PURCHASE;APR> != “None” or is NOT equal to <GOTO;PURCHASE;APR>.

I don't know what you're trying to achieve with

Intro[@Tier = *]

what this actually means is "select all the Intro elements whose @Tier attribute is equal to one of their child elements".

This clause also looks wrong:

not(Purchase/@APR != /Goto[@Tier = *]/Purchase/@APR)

/Goto will select a Goto element at the top level of the document. You haven't shown the top level of your document, but somehow I doubt it is a Goto element.

I suspect you're trying to construct a join query using "*" as a range variable. Joins are quite hard (sometimes impossible) in a single XPath 1.0 expression. You probably need to move up to the XSLT level:

<xsl:variable name="top" select="."/>
  <xsl:for-each select="Intro">
    <xsl:variable name="Tier" select="@Tier"/>
    <xsl:for-each select="$top/Goto">
      <xsl:if test="@Tier != $Tier">...





Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old January 29th, 2008, 02:32 PM
Registered User
 
Join Date: Jan 2008
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to fedehf
Default

Thank you for replying.
I came up with a pretty long logic that works:

Code:
 <xsl:variable name="IntroTiers" select="Intro[@Tier = '1' and Purchase/@APR!='None' and BT/@APR!='None' and Purchase/@APR != /CCAP/Goto[@Tier = '1']/Purchase/@APR and BT/@APR != /CCAP/Goto[@Tier = 1]/BT/@APR and not(*/@APR = preceding-sibling::Intro/*/@APR) or
    @Tier = '2' and Purchase/@APR!='None' and BT/@APR!='None' and Purchase/@APR != /CCAP/Goto[@Tier = '2']/Purchase/@APR and BT/@APR != /CCAP/Goto[@Tier = 2]/BT/@APR and not(*/@APR = preceding-sibling::Intro/*/@APR) or
    @Tier = '3' and Purchase/@APR!='None' and BT/@APR!='None' and Purchase/@APR != /CCAP/Goto[@Tier = '3']/Purchase/@APR and BT/@APR != /CCAP/Goto[@Tier = 3]/BT/@APR and not(*/@APR = preceding-sibling::Intro/*/@APR) or
    @Tier = '4' and Purchase/@APR!='None' and BT/@APR!='None' and Purchase/@APR != /CCAP/Goto[@Tier = '4']/Purchase/@APR and BT/@APR != /CCAP/Goto[@Tier = 4]/BT/@APR]/@Tier " />


It's not a generic logic because I couldn't figure out how to do it but this one worked just fine.

Anyway, thanks.

 
Old January 29th, 2008, 03:04 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Not nice. You didn't say whether you're using XPath 1.0 or 2.0. In 2.0 you can reduce this a bit, something like this if I understand it right:

<xsl:variable name="IntroTiers" select="
Intro[some $t in 1 to 4 satisfies (@Tier = $t and Purchase/@APR!='None' and BT/@APR!='None' and Purchase/@APR != /CCAP/Goto[@Tier = $t]/Purchase/@APR and BT/@APR != /CCAP/Goto[@Tier = $t]/BT/@APR and not(*/@APR = preceding-sibling::Intro/*/@APR))]/@Tier " />

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old January 29th, 2008, 03:09 PM
Registered User
 
Join Date: Jan 2008
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to fedehf
Default

Here we use XPath 1.0






Similar Threads
Thread Thread Starter Forum Replies Last Post
Newbie XSLT question wasabi XSLT 2 March 8th, 2007 01:06 PM
Newbie Question sionfx VS.NET 2002/2003 0 November 16th, 2006 03:32 PM
generating a table w. xslt, newbie problem themuffinman_swe XSLT 5 November 26th, 2005 01:05 PM
XSLT Newbie needs help... Should be easy fix! C4 XSLT 1 November 21st, 2005 04:11 AM
Newbie: XSLT & Scripts kwilliams XSLT 13 August 5th, 2005 11:39 AM





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