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 August 26th, 2008, 10:40 AM
Registered User
 
Join Date: Aug 2008
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Trouble combining node information: Please help

Hello. I have some raw XML that I am trying to transform before sending it to my web interface. I would like to combine the the ConditionText of the nodes that have no PriceAdjustments with the immediately following node that contains more information. Here is my XML. As an example I would like to combine the ConditionText for the first node with the ConditionText of the second node and not display to first node at all. Any help you can provide is much appreciated. Let me know if you need more info. I am at a loss as to how to do this. Thank you.

<Adjustments diffgr:id="Adjustments1" msdata:rowOrder="0">
  <PricingGroupID>2987</PricingGroupID>
  <InvestorRegionID>295</InvestorRegionID>
  <InvestorProductID>1014611</InvestorProductID>
  <ConditionText>IF FICO >= 660</ConditionText>
  <Comment />
  <RuleIdentifier>16387021</RuleIdentifier>
  <DisplayOrder>1</DisplayOrder>
  </Adjustments>
- <Adjustments diffgr:id="Adjustments2" msdata:rowOrder="1">
  <PricingGroupID>2987</PricingGroupID>
  <InvestorRegionID>295</InvestorRegionID>
  <InvestorProductID>1014611</InvestorProductID>
  <ConditionText>AND LTV <= 75.%</ConditionText>
  <PriceAdjustment>-0.125</PriceAdjustment>
  <RateAdjustment>0.000</RateAdjustment>
  <MarginAdjustment>0.000</MarginAdjustment>
  <SRPAdjustment>0.000</SRPAdjustment>
  <Comment />
  <RuleIdentifier>16387021</RuleIdentifier>
  <DisplayOrder>2</DisplayOrder>
  </Adjustments>
- <Adjustments diffgr:id="Adjustments3" msdata:rowOrder="2">
  <PricingGroupID>2987</PricingGroupID>
  <InvestorRegionID>295</InvestorRegionID>
  <InvestorProductID>1014611</InvestorProductID>
  <ConditionText>IF $100,000 <= Loan Amount < $150,000</
ConditionText>
  <PriceAdjustment>0.050</PriceAdjustment>
  <RateAdjustment>0.000</RateAdjustment>
  <MarginAdjustment>0.000</MarginAdjustment>
  <SRPAdjustment>0.000</SRPAdjustment>
  <Comment />
  <RuleIdentifier>16387261</RuleIdentifier>
  <DisplayOrder>3</DisplayOrder>
  </Adjustments>
- <Adjustments diffgr:id="Adjustments4" msdata:rowOrder="3">
  <PricingGroupID>2987</PricingGroupID>
  <InvestorRegionID>295</InvestorRegionID>
  <InvestorProductID>1014611</InvestorProductID>
  <ConditionText>IF State is TEXAS</ConditionText>
  <Comment />
  <RuleIdentifier>16387667</RuleIdentifier>
  <DisplayOrder>4</DisplayOrder>
  </Adjustments>
- <Adjustments diffgr:id="Adjustments5" msdata:rowOrder="4">
  <PricingGroupID>2987</PricingGroupID>
  <InvestorRegionID>295</InvestorRegionID>
  <InvestorProductID>1014611</InvestorProductID>
  <ConditionText>AND Waive Escrows is No</ConditionText>
  <PriceAdjustment>-0.200</PriceAdjustment>
  <RateAdjustment>0.000</RateAdjustment>
  <MarginAdjustment>0.000</MarginAdjustment>
  <SRPAdjustment>0.000</SRPAdjustment>
  <Comment />
  <RuleIdentifier>16387667</RuleIdentifier>
  <DisplayOrder>5</DisplayOrder>
  </Adjustments>
- <Adjustments diffgr:id="Adjustments6" msdata:rowOrder="5">
  <PricingGroupID>2987</PricingGroupID>
  <InvestorRegionID>295</InvestorRegionID>
  <InvestorProductID>1014611</InvestorProductID>
  <ConditionText>Total Adjustments</ConditionText>
  <PriceAdjustment>-0.275</PriceAdjustment>
  <RateAdjustment>0.000</RateAdjustment>
  <MarginAdjustment>0.000</MarginAdjustment>
  <SRPAdjustment>0.000</SRPAdjustment


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

At the point where the second Adjustments element is the context node, you can do

<ConditionText>
  <xsl:value-of select="preceding-sibling::Adjustments[1]/ConditionText"/>
  <xsl:value-of select="ConditionText"/>
</ConditionText>



Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer's Reference
 
Old August 26th, 2008, 11:31 AM
Registered User
 
Join Date: Aug 2008
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

First of all, I have been working on this forever. Thank you. Finally. Progress. It does however, lead me to a secondary issue. How to dynamically decide if I need to combine with the preceeding node or not. The code works as expected, I just don't know the correct way to determine whether it should This is my current output and xslt:

XSLT: I want to test if there is a price adjustment before I render the the condition.
<xsl:if test="PriceAdjustment">
<xsl:attribute name="condition">
<xsl:value-of select="preceding-sibling::Adjustments[1]/ConditionText"/>
<xsl:value-of select="ConditionText"/>
</xsl:attribute>
</xsl:if>

<xsl:if test="PriceAdjustment">
<xsl:attribute name="price">
<xsl:value-of select="number(PriceAdjustment)"/>
</xsl:attribute>
</xsl:if>



Output: This works, but I need to combine the conditions, well, conditionally.

<product_adjustment condition="IF FICO &gt;= 660 AND LTV &lt;= 75.%" price="-0.125" rate="0" margin="0" srp="0" />

<product_adjustment condition=" AND LTV &lt;= 75.%IF $100,000 &lt;= Loan Amount &lt; $150,000" price="0.05" rate="0" margin="0" srp="0" />

<product_adjustment />

<product_adjustment condition="IF State is TEXAS AND Waive Escrows is No" price="-0.2" rate="0" margin="0" srp="0" />

<product_adjustment condition=" AND Waive Escrows is No Total Adjustments" price="-0.275" rate="0" margin="0" srp="0" />

 
Old August 26th, 2008, 12:18 PM
Registered User
 
Join Date: Aug 2008
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I got it. Thank you so much for your help.

<xsl:if test="PriceAdjustment">
<xsl:choose>
<xsl:when test="string-length(normalize-space($priceAdjustment)) > 0">
<xsl:attribute name="condition">
<xsl:value-of select="normalize-space(ConditionText)"/>
</xsl:attribute>
</xsl:when>
<xsl:otherwise>
<xsl:attribute name="condition">
<xsl:value-of select="normalize-space($testCondition)"/>
<xsl:value-of select="normalize-space(ConditionText)"/>
</xsl:attribute>
</xsl:otherwise>
</xsl:choose>
</xsl:if>






Similar Threads
Thread Thread Starter Forum Replies Last Post
The reference node is not a child of this node.XSL XMLUser XSLT 2 February 25th, 2008 05:22 AM
how to append child node after an node in XML + C# vishnu108mishra XML 5 November 13th, 2007 05:30 AM
Missing Node (Node data) pashworth XSLT 3 January 29th, 2007 12:39 PM
retrieving information from a parent node Tomi XSLT 2 September 6th, 2006 06:54 AM
Copying Source Node attributes to output node pvsat XSLT 2 November 3rd, 2005 09:46 AM





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