XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Show tree view Topic
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Postnext
Don BerningSubject: XSL error
Author: Don Berning
Date: 07 Feb 2007 09:19 AM
I am running a transformation on XML and the reply that I am getting is not correct and didn't know what to try. Sample of the data is below. the Output should on give back "250" and not "250 275"

Scenario XML

<Policy>
<Premium>
<CoveragePremium>
<Type ID="P">
<Description>Full Term Premium</Description>
</Type>
<PremiumAmount>250</PremiumAmount>
</CoveragePremium>
</Premium>
<Premium>
<CoveragePremium>
<Type ID="PRP">
<Description>ProRatedPremium</Description>
</Type>
<PremiumAmount>275</PremiumAmount>
</CoveragePremium>
</Premium>
</Policy>


XSL Transformation

<?xml version="1.0"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<URS xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Premium>
<ABC>
<xsl:if test="Policy/Premium/CoveragePremium/Type/@ID='P'">
<xsl:value-of select="Policy/Premium/CoveragePremium/PremiumAmount"/>
</xsl:if>
</ABC>
</Premium>
</URS>
</xsl:template>
</xsl:stylesheet>


Output

<?xml version="1.0" encoding="UTF-8"?>
<URS xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Premium>
<ABC>250 275</ABC>
</Premium>
</URS>

Posttop
Tony LavinioSubject: XSL error
Author: Tony Lavinio
Date: 07 Feb 2007 09:50 AM
You may want to move things around a little, but I've attached a
stylesheet that probably will work better for you.

Remember that the XPath selections work across the entire document,
so that this:
test="Policy/Premium/CoveragePremium/Type/@ID='P'"
means find any ID attribute within any Type element within any Premium
element within any Policy element under the current element.

And also it means that:
select="Policy/Premium/CoveragePremium/PremiumAmount"
means return the set of all PremiumAmount elements under all
CoveragePremium elements under all Premium elements under all Policy
elements under the current element.

So, using either xsl:apply-templates (the preferred method), or
xsl:for-each, you can set the context to the parent of just the
part of the XML tree you are interested in. Then your test and
selection make more sense, since they have a related context.

I find it easiest to just drag things from the right-hand document
tree when writing XSLT; that's what I did here, since the XSLT editor
understands the context it puts in just the part of the path that is
relevant.


Documentdon.xsl
Amended stylesheet

 
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.