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
Brian McNamaraSubject: Newbie: HELP! How to do simple transforms and defaults visually in Stylus ?
Author: Brian McNamara
Date: 25 Jan 2005 05:02 PM
Dear Stylus,

HELP!

I'm testing your product (and Altova's) for my company. I only have one or two days to answer these questions!

I have (at least) two things I need to accomplish:


1. Most importantly, I need to take this decimal value:

123.4

and convert it to this string value

0000012340+

In other words, multiply by 100 (if possible), force two (implied) decimal places, make the total length 11 with leading zeros and a plus or minus sign on the end, depending.

In Altova, I can do all this visually. I don't need to actually write an XSLT code. Can Stylus do this visually?



2. I have two schemas defined, both with the same elemenys. I need to create an XSLT from them, such that if FIELD_A is ABSENT in the input XML instance, a default value is entered into the output XML instance.

For instance:

I have a "FROM.xml", that could contain from 1 to 3 separate elements. I want to use XSLT to map that to a new "TO.xml", which has the same elements, but must contain all 3, in the correct order. If the element isn't found in the FROM.xml instance, I need to move a hard-coded default to the the same element in TO.xml.

So I want to take this FROM.xml:

<root>
<ELEMENT_B>some real value</ELEMENT_B>
</root>

and generate this TO.xml:

<root>
<ELEMENT_A>some default value</ELEMENT_A>
<ELEMENT_B>some real value</ELEMENT_B>
<ELEMENT_C>some other default value</ELEMENT_C>
</root>

Is this possible with Stylus? If so, how?

I don't know if this matters, but I have XSD's defined for both XML's. I have tried making all the elements a sequence in the TO.xsd, but MapForce seems to ignore that.

HELP! HELP! HELP!

Thanks a lot!
--Brian

Postnext
Ivan PedruzziSubject: Newbie: HELP! How to do simple transforms and defaults visually in Stylus ?
Author: Ivan Pedruzzi
Date: 25 Jan 2005 07:15 PM

The following code does moltiplication and padding, and will run on any XSLT 1.0
compliant processor.

<xsl:variable name="val" select="@bookid * 100"/>
<xsl:value-of select= "concat( substring('00000000000', 1, (11 - string-length($val)) ), substring($val, 1, 11))"/>

To map a set of elements with fallback default values do the following

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">

<root>
<xsl:apply-templates select="root"/>
</root>

</xsl:template>

<xsl:template match="root">

<ELEMENT_A>
<xsl:choose>
<xsl:when test="ELEMENT_A"><xsl:value-of select="ELEMENT_A"/></xsl:when>
<xsl:otherwise>default A</xsl:otherwise>
</xsl:choose>
</ELEMENT_A>

<ELEMENT_B>
<xsl:choose>
<xsl:when test="ELEMENT_B"><xsl:value-of select="ELEMENT_B"/></xsl:when>
<xsl:otherwise>default B</xsl:otherwise>
</xsl:choose>
</ELEMENT_B>

<ELEMENT_C>
<xsl:choose>
<xsl:when test="ELEMENT_C"><xsl:value-of select="ELEMENT_C"/></xsl:when>
<xsl:otherwise>default C</xsl:otherwise>
</xsl:choose>
</ELEMENT_C>

</xsl:template>

</xsl:stylesheet>

Postnext
Brian McNamaraSubject: Newbie: HELP! How to do simple transforms and defaults visually in Stylus ?
Author: Brian McNamara
Date: 26 Jan 2005 12:07 PM
Dear Ivan,

Thank you so much for your response to my XSLT question. That was very helpful.

Would you be able to help me with a follow-up question?

In MapForce, I would be able to visually draw an equivalent of the XSLT code you sent me, put it in it’s own box, label it, and re-use it visually. For instance, I could take something like:

<xsl:variable name="val" select="@bookid * 100"/>
<xsl:value-of select= "concat( substring('00000000000', 1, (11 - string-length($val)) ), substring($val, 1, 11))"/>

and label it “Convert_Decimal_to_Dollar_String”. I could define an “input” to the box.


Then, I could drag that box into my visual XSLT builder, and draw a line from the “FROM”, to the new box, and then to the “TO”.

Is that possible with Stylus? (Again, I’m brand new to Stylus. Maybe this is obvious…)


Thank you once again for your help.


--Brian McNamara

Sr. Software Development Manager
Focus Technology Group
(978)535-9626


Posttop
Ivan PedruzziSubject: Newbie: HELP! How to do simple transforms and defaults visually in Stylus ?
Author: Ivan Pedruzzi
Date: 27 Jan 2005 12:51 AM

Create a second XSLT that will be your library of utilities

------------------------------------------------------
padding.xsl

<?xml version='1.0'?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template name="padding">
<xsl:param name="number"/>
<xsl:param name="digits" select="11"/>
<xsl:variable name="val" select="$number * 100"/>
<xsl:value-of select= "concat( substring('00000000000', 1, (11 - string-length($val)) ), substring($val, 1, 11))"/>
</xsl:template>

</xsl:stylesheet>

then in the main XSLT import padding.xsl and invoke the template "padding"

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:import href="padding.xsl"/>

<xsl:template match="/">
<root>
<value>
<xsl:call-template name="padding">
<xsl:with-param name="$number" select="value"/>
</xsl:call-template>
</value>
</root>
</xsl:template>

</xsl:stylesheet>

Ivan

 
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.