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
Conferences Close Tree View
+ Stylus Studio Feature Requests (1192)
+ Stylus Studio Technical Forum (14621)
+ Website Feedback (249)
- XSLT Help and Discussion (7625)
-> - XSLT slicing and orphan contro... (1)
-> + How to delete CDATA using XSL... (15)
-> + Remove only root namespace, bu... (3)
-> + String Parsing (3)
-> + Calling Java method from XSL (3)
-> + populate xsl file from xsd fil... (5)
-> + formating a number like #'###.... (3)
-> + Help with grouping children, f... (20)
-> + Need help for newbie! (3)
-> + xpath in string format (2)
-> + How to populate elements at ra... (4)
-> + Changing Date format in XLST (2)
-> + Please help....How could I rem... (2)
-> + Counting children and grandchi... (7)
-> + Nested tags (4)
-> + Problem with XSLT on a Soap En... (2)
-> + Problem with XSLT on a Soap En... (5)
-> + Comparison between XSLT proces... (2)
-> - Printing non-existing value (9)
-> ->Printing non-existing val...
-> ->Printing non-existing val...
-> ->Printing non-existing val...
-> ->Printing non-existing val...
-> ->Printing non-existing val...
-> ->Printing non-existing val...
-> ->Printing non-existing val...
-> ->Printing non-existing val...
-> + big input file for XSLT (14)
-> + Is there any way to store xpat... (2)
-> + Encoding special charecters (2)
-> + Sorting (3)
-> + XML to PDF using XSL:FO (3)
-> + How to find the line number in... (2)
-> + How to set a marker for paper ... (2)
-> + Not equality Function (2)
-> + Counting Elements (4)
-> + Looking for help or code samp... (2)
-> + Help needed in pattern matchin... (2)
-> + Repeaters and Ifs (2)
-> + select adjacent nodes in xpath... (3)
-> + Stripping of Empty Target Elem... (2)
-> + auto-generate Edifact Intercha... (5)
-> + Qname Error in xsl:element (2)
-> + [Newbie] Type conversion and f... (2)
-> + Do ...when (2)
-> + Using Key (3)
-> + sorting elements in option (2)
-> + NaN(not available) value repla... (3)
-> + infinite loop error when tryin... (9)
-> + Escape a character in the stri... (3)
-> + find sum of 2 elements in xml (2)
-> + placing a ' * ' by reading the... (3)
-> + Problem in dispaying Current D... (4)
-> + Merging Table Cells in XSLT re... (3)
-> + xsl fo block-container and foo... (2)
-> + Is is possible to create a .CO... (2)
-> + printing a parent node value i... (2)
-> + Mime header info setup? (3)
-> + Calculating a Date based on 4 ... (3)
-> + XSLT formatting number issue (10)
-> + map repeating elements separat... (3)
-> + Combining XML elements based o... (3)
-> + Convert XML to UTF-8 (8)
-> + XSLT and MS Access 2007 Optio... (5)
-> - WORDML list to XML list (1)
-> + [Newbie] Using lookups in XSLT... (3)
-> + Comparing 2 passed Date Values (2)
-> + ERROR XQueryMediator Error du... (2)
-> + XML / XSLT... Unordered lists ... (2)
-> + Specify image path in XSL (2)
-> + Variable within a variable (3)
-> + How to call jfreechart method ... (8)
-> + leading and trailing white spa... (2)
-> + XSLT to Html problems (6)
-> + How to set classpath, when i n... (3)
-> + Error in using functions (4)
-> + To find the occurence of a cha... (3)
-> + PLMXML to XML (4)
-> + Transform multiple node values... (2)
-> + I am in need of svg example(s)... (13)
-> + count in XSLT, Need Help Pleas... (2)
-> + Help with XML.Report and Gener... (2)
-> + for each loop and variable (5)
-> + Problem with selecting nodes f... (3)
-> + Getting "Expected elemenmt mis... (2)
-> + Help with attached XML mapping... (8)
-> + xml:space="Preserve" and Embed... (2)
-> + XSLT and Multiple Strings (2)
-> + XSL Date format (2)
-> + check element contents against... (3)
-> + XML to XML Namespace conversio... (2)
-> - Supressing subgroup headers in... (1)
-> - HTML to fo conversion using XS... (1)
-> + No Topic (2)
-> + parsing xml using xslt HELP (2)
-> + Multiple Page Headers (2)
-> + PLM Xml To Generic XML (3)
-> + XSLT/XPath Help (2)
-> + XSL Space Issue (2)
-> + wanting help with xslt custom ... (3)
-> - Update input xml content with ... (1)
-> + Error: namespace prefix xsl on... (3)
-> + Error in my xsl:if test... (2)
-> - calling javascript from XSLT (1)
-> + Error when trying to a call a ... (2)
-> - HTTP POST from XSLT (1)
-> + passing xml document as input ... (2)
-> + XSLT for WORDML table to CALS ... (2)
-- Previous [361-380] [381-400] [401-420] Next
+ XQuery Help and Discussion (2017)
+ Stylus Studio FAQs (159)
+ Stylus Studio Code Samples & Utilities (364)
+ Stylus Studio Announcements (113)
Topic  
Postnext
prasad ramaSubject: Printing non-existing value
Author: prasad rama
Date: 06 Feb 2009 08:02 PM
Hi,

I have the xml like this

<states>
<state abbr="AR" label="Arkansas">
<product code="DFRO" title="FIXED RATE OPTIONS FOR DISCONTINUED EQ. CREDITLINE"/>
<product code="EMS" title="HOME EQUITY LINE OF CREDIT (HELOC)"/>
<product code="HE2" title="HOME EQUITY LOAN"/>
</state>
<state abbr="AZ" label="Arizona">
<product code="DFRO" title="FIXED RATE OPTIONS FOR DISCONTINUED EQ. CREDITLINE"/>
<product code="FRO" title="FIXED RATE LOAN OPTIONS"/>
<product code="HE2" title="HOME EQUITY LOAN"/>
</state>
<state abbr="VA" label="Virginia">
<product code="DFRO" title="FIXED RATE OPTIONS FOR DISCONTINUED EQ. CREDITLINE" />
<product code="EMS" title="HOME EQUITY LINE OF CREDIT (HELOC)" />
<product code="FRO" title="FIXED RATE LOAN OPTIONS" />
<product code="HE2" title="HOME EQUITY LOAN" />
</state>
</states>

I need to the output like...

Arkansas
____________________________________
DFRO | EMS | FRO | None
____________________________________
Arizona
____________________________________
DFRO | None | FRO | HE2
____________________________________
Virginia
____________________________________
DFRO | EMS | FRO | HE2

But according to my xsl code..

<xsl:key name="product" match="/states/state/product" use="concat(../@abbr,@code)"/>
<xsl:template match="/">
<html>
<body>
<table border="1" width="100%" cellpadding="0" cellspacing="0">
<xsl:for-each select="/states/state">
<xsl:variable name="state" select="@abbr"/>
<tr>
<td colspan="5" align="center">
<xsl:value-of select="@label"/>
</td>
<tr>
<xsl:for-each select="//product[generate-id()=generate-id(key('product',concat($state,@code))[1])]">
<td>
<xsl:value-of select="@code"/>
</td>
</xsl:for-each>
</tr>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>

I am getting like this...

DFRO | EMS | FRO
____________________________________
Arizona
____________________________________
DFRO | FRO | HE2
____________________________________
Virginia
____________________________________
DFRO | EMS | FRO | HE2


I need to print "None" value when the products are not exists in particular state.

Can any one tell me how to check the values, when the data was given like this.

Thank you,

Postnext
John BamptonSubject: Printing non-existing value
Author: John Bampton
Date: 07 Feb 2009 09:06 PM
Originally Posted: 07 Feb 2009 07:51 AM
[Webmaster: removed email]

This should work, its a bit verbose but works.

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:template match="/">
<html>
<head></head>
<body>
<table>
<xsl:for-each select="states/state">
<tr>
<td colspan="4"><xsl:value-of select="@label"></xsl:value-of></td>
</tr>
<tr>
<xsl:choose>
<xsl:when test="product[1]/attribute::code = 'DFRO' or product[2]/attribute::code = 'DFRO' or product[3]/attribute::code = 'DFRO' or product[4]/attribute::code = 'DFRO' ">
<td>DFRO</td>
</xsl:when>
<xsl:otherwise>
<td>NONE</td>
</xsl:otherwise>
</xsl:choose>
<xsl:choose>
<xsl:when test="product[1]/attribute::code = 'EMS' or product[2]/attribute::code = 'EMS' or product[3]/attribute::code = 'EMS' or product[4]/attribute::code = 'EMS' ">
<td>EMS</td>
</xsl:when>
<xsl:otherwise>
<td>NONE</td>
</xsl:otherwise>
</xsl:choose>
<xsl:choose>
<xsl:when test="product[1]/attribute::code = 'FRO' or product[2]/attribute::code = 'FRO' or product[3]/attribute::code = 'FRO' or product[4]/attribute::code = 'FRO' ">
<td>FRO</td>
</xsl:when>
<xsl:otherwise>
<td>NONE</td>
</xsl:otherwise>
</xsl:choose>
<xsl:choose>
<xsl:when test="product[1]/attribute::code = 'HE2' or product[2]/attribute::code = 'HE2' or product[3]/attribute::code = 'HE2' or product[4]/attribute::code = 'HE2' ">
<td>HE2</td>
</xsl:when>
<xsl:otherwise>
<td>NONE</td>
</xsl:otherwise>
</xsl:choose>
<hr></hr>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

Cheers. John Bampton.

Postnext
prasad ramaSubject: Printing non-existing value
Author: prasad rama
Date: 07 Feb 2009 07:06 PM
Hi John,

I really appreciate for your response. I provided only some part of the data from the XML file. The actual XML file is so big. It has so many states and products.

We can not take care of all the states and products with the code you provided, that means we can not expect states and their products.

So I we need to dynamically place the "None" values where we do not have the products.

Please give any suggestions.

Thanks once again.

Postnext
John BamptonSubject: Printing non-existing value
Author: John Bampton
Date: 08 Feb 2009 10:01 AM
Here try this solution, it uses SAXON.


<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"
extension-element-prefixes="saxon"
xmlns:saxon="http://saxon.sf.net/">

<xsl:variable name="counter" select="1" saxon:assignable="yes"/>
<xsl:variable name="productcount" select="5"></xsl:variable>
<xsl:variable name="exists" select="0" saxon:assignable="yes"></xsl:variable>


<xsl:template match="/">
<html>
<head></head>
<body>
<table>
<xsl:for-each select="states/state">
<tr>
<td colspan="4"><xsl:value-of select="@label"></xsl:value-of></td>
</tr>
<tr>
<saxon:while test="$counter &lt; $productcount">
<xsl:choose>
<xsl:when test="product[$counter]/attribute::code = 'DFRO' ">
<td>DFRO</td>
<saxon:assign name="exists" select="1"/>
</xsl:when>
</xsl:choose>
<xsl:choose>
<xsl:when test="$exists = 1 ">
<saxon:assign name="counter" select="$productcount"/>
</xsl:when>
<xsl:otherwise>
<saxon:assign name="counter" select="$counter+1"/>
</xsl:otherwise>
</xsl:choose>
</saxon:while>
<xsl:if test="$exists = 0">
<td>NONE</td>
</xsl:if>
<saxon:assign name="exists" select="0"/>
<saxon:assign name="counter" select="1"/>



<saxon:while test="$counter &lt; $productcount">
<xsl:choose>
<xsl:when test="product[$counter]/attribute::code = 'EMS' ">
<td>EMS</td>
<saxon:assign name="exists" select="1"/>
</xsl:when>
</xsl:choose>
<xsl:choose>
<xsl:when test="$exists = 1 ">
<saxon:assign name="counter" select="$productcount"/>
</xsl:when>
<xsl:otherwise>
<saxon:assign name="counter" select="$counter+1"/>
</xsl:otherwise>
</xsl:choose>
</saxon:while>
<xsl:if test="$exists = 0">
<td>NONE</td>
</xsl:if>
<saxon:assign name="exists" select="0"/>
<saxon:assign name="counter" select="1"/>


<saxon:while test="$counter &lt; $productcount">
<xsl:choose>
<xsl:when test="product[$counter]/attribute::code = 'FRO' ">
<td>FRO</td>
<saxon:assign name="exists" select="1"/>
</xsl:when>
</xsl:choose>
<xsl:choose>
<xsl:when test="$exists = 1 ">
<saxon:assign name="counter" select="$productcount"/>
</xsl:when>
<xsl:otherwise>
<saxon:assign name="counter" select="$counter+1"/>
</xsl:otherwise>
</xsl:choose>
</saxon:while>
<xsl:if test="$exists = 0">
<td>NONE</td>
</xsl:if>
<saxon:assign name="exists" select="0"/>
<saxon:assign name="counter" select="1"/>



<saxon:while test="$counter &lt; $productcount">
<xsl:choose>
<xsl:when test="product[$counter]/attribute::code = 'HE2' ">
<td>HE2</td>
<saxon:assign name="exists" select="1"/>
</xsl:when>
</xsl:choose>
<xsl:choose>
<xsl:when test="$exists = 1 ">
<saxon:assign name="counter" select="$productcount"/>
</xsl:when>
<xsl:otherwise>
<saxon:assign name="counter" select="$counter+1"/>
</xsl:otherwise>
</xsl:choose>
</saxon:while>
<xsl:if test="$exists = 0">
<td>NONE</td>
</xsl:if>
<saxon:assign name="exists" select="0"/>
<saxon:assign name="counter" select="1"/>

<hr></hr>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>


Cheers, John Bampton

Postnext
John BamptonSubject: Printing non-existing value
Author: John Bampton
Date: 09 Feb 2009 06:44 AM
I can see an even faster way of doing it based on the code I just gave you.

Postnext
James DurningSubject: Printing non-existing value
Author: James Durning
Date: 09 Feb 2009 11:28 AM
The key is creating a temporary variable to the state node, and then getting all the code values.

<xsl:for-each select="/states/state">
<xsl:variable name="state" select="."/> <!-- create pointer to current node -->
...
<xsl:for-each select="//product[not(@code = preceding::product/@code)]/@code"><!-- get all unique codes -->
<td>
<xsl:choose>
<xsl:when test="$state/product[@code = current()]">
<xsl:value-of select="."/>
</xsl:when>
<xsl:otherwise>None</xsl:otherwise>
</xsl:choose>
</td>
</xsl:for-each>

Postnext
prasad ramaSubject: Printing non-existing value
Author: prasad rama
Date: 09 Feb 2009 01:17 PM
Hi John,

I am using xml and xslt with .Net (dotNet). I can not use Saxon. Is while condition available in Xsl 1.0 version? Can you suggest me anyother alternative to solve this.

Thanks,

Hi James,

Thank you for replying to the post. I tried with your code snippet. It works properly with the data I posted above. But I added some more states & products and tried, it failed.

Thanks,

Postnext
John BamptonSubject: Printing non-existing value
Author: John Bampton
Date: 10 Feb 2009 03:00 AM
You can use Saxon.net which is a .net port of Saxon. That way you get support for XSLT/XPATH 2.0. .NET only supports XSLT 1.0.

Posttop
prasad ramaSubject: Printing non-existing value
Author: prasad rama
Date: 10 Feb 2009 07:58 PM
No, I can not use Saxon.

I have the data like this

{state abbr='TX'}
{product code="VA"}
{tier custom="240" ltv="0.01" min_amount="5000" rate="9.23" /}
{tier custom="240" ltv="10.01" min_amount="5000" rate="9.23" /}
{tier custom="240" ltv="20.01" min_amount="5000" rate="2.78" /}

{tier custom="240" ltv="0.01" min_amount="20000" rate="10.12" /}
{tier custom="240" ltv="10.01" min_amount="20000" rate="1.63" /}
{tier custom="240" ltv="20.01" min_amount="20000" rate="5.45" /}

{tier custom="240" ltv="30.01" min_amount="25000" rate="4.54" /}
{/product}
{product code=" "}
...............
...............
{/product}
{/state}

The output should look like this

Ltv(0) Ltv(10) Ltv(20)
Loan_amount(5000) 9.23 9.23 2.78

Loan_amount(20000) 10.12 1.63 5.45

Loan_amount(25000) None None 4.54

But with my code, I am getting the result like this

Ltv(0) Ltv(10) Ltv(20)
Loan_amount(5000) 9.23 9.23 2.78

Loan_amount(20000) 10.12 1.63 5.45

Loan_amount(25000) 4.54

Where the rate 4.54 should be in the 3rd column.

Here is my xsl..

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:key name="lien" match="/states/state/product/tier" use="concat(../../@abbr,../@code,@min_custom)"/>
<xsl:key name="ltv" match="/states/state/product/tier" use="concat(../../@abbr,../@code,@min_custom,@min_loan_amount,@min_ltv)"/>
<xsl:key name="loan" match="/states/state/product/tier" use="concat(../../@abbr,../@code,@min_custom,@min_loan_amount)"/>
<xsl:template match="/">
<html>
<body>
<table border="1" cellpadding="0" cellspacing="0">
<xsl:for-each select="/states/state[@abbr='TX']/product[@code='EMS']">
<xsl:for-each select="//tier[generate-id()=generate-id(key('lien',concat('TX','EMS','1'))[1])]">
<xsl:sort select="@min_custom" data-type="number" order="descending"/>
<xsl:variable name="custom" select="@min_custom"/>
<xsl:for-each select="../tier[generate-id()=generate-id(key('loan',concat('TX','EMS',$custom,@min_loan_amount))[1])]">
<xsl:sort select="@min_loan_amount" data-type="number" order="ascending"/>
<xsl:variable name="loan" select="@min_loan_amount"/>
<tr>
<td>
<xsl:value-of select="$loan"/>
</td>
<xsl:for-each select="../tier[generate-id()=generate-id(key('ltv',concat('TX','EMS',$custom,$loan,@min_ltv))[1])]">
<xsl:sort select="@min_ltv" data-type="number" order="ascending"/>
<td>
<xsl:value-of select="@rate"/>
</td>
</xsl:for-each>
</tr>
</xsl:for-each>
</xsl:for-each>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

In the above Xsl code, I am looping thru the nodes which has distinct custom, loan_amount and ltv values. For the 3rd loan_amount i.e, 25000 , we do not have the data for ltvs 0 and 10. So that the rate belongs to loan_amount 25000 is printing in the 1st position. I need to print that in the 3rd position.

To do that I need to loop thru loan_amount 25000 for 3 times, So that I can check for the condition and place "None" value if no data exists. Right now It loops thru only for once and if place any condition, it is not working.

Please suggest me how to solve this issue.

Thanks,

   
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.