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
Agustin EspinosaSubject: Mapper- How Not to Output nonexisting or empty elements
Author: Agustin Espinosa
Date: 22 Nov 2006 01:46 PM
Hi, Please help; I am trying to Transform an XML document into another XML document.
Using the mapper, it generates the following XSL:

XSL:
----
<?xml version='1.0' ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<Customer>
<CustName>
<xsl:value-of select="Customer/Name"/>
</CustName>
<CustAddress>
<CustProperty>
<CustPropertyNumber>
<xsl:value-of select="Customer/Address/Property/PropertyNumber"/>
</CustPropertyNumber>
</CustProperty>
<CustPropertyFlatNumber>
<xsl:value-of select="Customer/Address/PropertyFlatNumber"/>
</CustPropertyFlatNumber>
</CustAddress>
</Customer>
</xsl:template>
</xsl:stylesheet>


The Goal:
---------
Do Not output the tag : <CustPropertyFlatNumber> if is not existing or empty on the XML source.


Assuming XML Document source:
-----------------------------
<?xml version="1.0" encoding="UTF-8"?>
<Customer>
<Name>John</Name>
<Address>
<Property>
<PropertyNumber>456</PropertyNumber>
</Property>
</Address>
</Customer>


Current Result after applying XSL:
----------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<Customer>
<CustName>John</CustName>
<CustAddress>
<CustProperty>
<CustPropertyNumber>456</CustPropertyNumber>
</CustProperty>
<CustPropertyFlatNumber></CustPropertyFlatNumber>
</CustAddress>
</Customer>



Output needed:
--------------
<?xml version="1.0" encoding="UTF-8"?>
<Customer>
<CustName>John</CustName>
<CustAddress>
<CustProperty>
<CustPropertyNumber>456</CustPropertyNumber>
</CustProperty>
</CustAddress>
</Customer>


UnknownTestSource.xml
SourceXML

UnknownTestStyle.xsl
TestStyle

Postnext
Ivan PedruzziSubject: Mapper- How Not to Output nonexisting or empty elements
Author: Ivan Pedruzzi
Date: 22 Nov 2006 02:29 PM
Change the code as follow, you will se how it looks like in mapper

<xsl:if test="Customer/Address/PropertyFlatNumber">
<CustPropertyFlatNumber>
<xsl:value-of select="Customer/Address/PropertyFlatNumber"/>
</CustPropertyFlatNumber>
</xsl:if>


Hope this helps
Ivan Pedruzzi
Stylus Studio Team

Postnext
Agustin EspinosaSubject: Mapper- How Not to Output nonexisting or empty elements
Author: Agustin Espinosa
Date: 23 Nov 2006 06:20 AM
Ivan, Many Thanks for your help, it works Perfect.
As you can imagine I am new to XSL, Sorry didn't ask this before, Is it posible to apply the same (existence) logic to all the xml mappings, without writing an IF instruction for each element?
Regards
Agustin

Postnext
James DurningSubject: Mapper- How Not to Output nonexisting or empty elements
Author: James Durning
Date: 23 Nov 2006 04:14 PM
You could use a for-each statement:
<xsl:for-each select="Customer/Address/*">
<xsl:element name="concat('Cust', name())">
<xsl:value-of select="."/>
</xsl:element>
</xsl:for-each>

Posttop
Agustin EspinosaSubject: Mapper- How Not to Output nonexisting or empty elements
Author: Agustin Espinosa
Date: 24 Nov 2006 09:46 AM
Originally Posted: 24 Nov 2006 09:44 AM
Hi James, Thank you very much for your help; You have pointed me on the right direction. I will implement your suggestion. Regards
Agustin

 
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.