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)
-> + How to add page number in to v... (2)
-> + XSL Grouping (7)
-> + Repeat images using FOR EACH l... (7)
-> + How to get File name (2)
-> + image and text on the same lin... (2)
-> + Create XSLT stylesheets for us... (2)
-> + Merge Multiple Files While Che... (2)
-> + xslt 3 level or multi level gr... (6)
-> + How to create xsl which will c... (2)
-> + xsl:variable and Result Tree F... (7)
-> - XSL-FO fo:table continued from... (1)
-> + XSLT Java issue (2)
-> + problem with hyperlink (4)
-> + substring-after function probl... (4)
-> + Xalan Processing (3)
-> + Memory utilization high with m... (2)
-> + check all parent node groups s... (2)
-> + CSV DOC to XML CONVERSION (11)
-> + XSLT: Ordered List (based on r... (4)
-> + XSLT Mapping - Issue (4)
-> + XSL following-sibling, how to ... (5)
-> + need xslt elements help (2)
-> + Dynamic generation of URL in X... (2)
-> + List Created from Section Navi... (2)
-> + xslt elements help (2)
-> + Map field if source is not nul... (3)
-> + XSLT group and sort whith gene... (4)
-> + Nested XML value (2)
-> + Specifying condition with coun... (4)
-> + xsl:function using found in er... (4)
-> + How to remove an unwanted spac... (2)
-> + Question about variable substi... (2)
-> + XSL for Comparing nodes and di... (4)
-> + External lookup list (8)
-> + XSL HTML output now needs to b... (2)
-> + Adding a new sub element to th... (4)
-> + How do I get rid of 'Tip' node... (9)
-> + Trying to dynamically create n... (2)
-> + Display XML link, using XSLT a... (9)
-> + calling templates based on ord... (2)
-> + How to add internal links usin... (4)
-> + How to call user defined java ... (3)
-> + XSLT and WebApps past and futu... (3)
-> + passing condition through java... (3)
-> + Apllying a template from withi... (4)
-> + Getting xsl element in javascr... (3)
-> + The document() function inside... (3)
-> + Footnote text move to para (2)
-> + XSL: multiple element come to ... (3)
-> + How to use following-sibling &... (2)
-> + How to use FOP 0.95 with Stylu... (4)
-> + Error during creating PDF from... (2)
-> + Help creating a comma delimite... (4)
-> + Selective Add using XSLT recur... (3)
-> + Help: convert without parent e... (2)
-> - Correct my substring function ... (1)
-> + Old xsl into reports (4)
-> + How to save xslt converted fil... (3)
-> + How to find non tagging text? (5)
-> + Help: Hex entity to Character... (6)
-> + EDI QUOTES MESSAGE NEED TO REP... (2)
-> + How to convert in multi level ... (4)
-> + Need some help with a styleshe... (3)
-> - Conditional Formattinf Formula... (1)
-> + Creating HTML Unordered LIsts.... (2)
-> + xslt params uknown number of i... (2)
-> + How to use fonts other than ba... (2)
-> - Converting existing HTML into ... (1)
-> + Help to tune up this XSLT (2)
-> + XSLT - is only converting the ... (2)
-> + XSLT Editor tab (4)
-> + Convert multiple files from XM... (2)
-> + how to use in select expressi... (2)
-> + Help needed in XSL transformat... (2)
-> + How to add a string with math ... (5)
-> + How to add a string with math ... (6)
-> - br element (1)
-> + Stylesheet directed terminatio... (2)
-> + Who can help me whit sum funct... (2)
-> + XSLT Works in Stylus Studio, n... (3)
-> - Filter by Attribute (1)
-> + Display x number of items whic... (6)
-> + MultiColumn Reporting (3)
-> + cant get namespace declaration... (3)
-> + Performance xsl:for each and n... (3)
-> + How to assign value to a XSLT ... (3)
-> + Select element value based on ... (2)
-> + Version 10 of Saxon? (8)
-> + How to get the value of a node... (5)
-> + Display Xpath using (4)
-> + XSLT to report (2)
-> + xslt help for a noobie (2)
-> + XSL-FO XML to PDF with XSLT (3)
-> + Using XSLT to transform XML to... (4)
-> + XSLT to sort a list alphabetic... (4)
-> + How to Get Colum Values based ... (2)
-> + non persisting predicate filte... (5)
-> + HTML to XSLT (2)
-> + extra carriage returns in "csv... (2)
-> + extra carriage returns in "csv... (3)
-- Previous [301-320] [321-340] [341-360] 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.