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
Rahul PuttaguntaSubject: xml, xslt question
Author: Rahul Puttagunta
Date: 03 Oct 2006 07:29 PM
Originally Posted: 03 Oct 2006 07:26 PM
Would you please help me create an xsl stylesheet?

I need to transform this xml using an xslt stylesheet. I basically need to trim spaces from the attributes and then save it into another xml file.
Since the post is trimming it for me, I am replacing the spaces with
X's.

Source:

<searchresults>

<v w="21XXXXXXXXXXXXXXXXX">
<f n="BrandCode" v="1XXXXXXXXXXXXXXX"/>
<f n="state" v="AKXXXXXXXXXXXXXXXXXX"/>
<f n="city" v="AnchorageXXXXXXXXXXX"/>
<f n="name" v="name1"/>


</v>
<v w="21">
<f n="BrandCode" v="7"/>
<f n="state" v="AKXXXXXXXXXXXXXXXXX"/>
<f n="city" v="FairbanksXXXXXXXXXXXXXXXXXXX"/>
<f n="name" v="name2"/>

</v>
</searchresults>


Result:

<searchresults>

<v w="21">
<f n="BrandCode" v="1"/>
<f n="state" v="AK"/>
<f n="city" v="Anchorage"/>
<f n="name" v="name1"/>


</v>
<v w="21">
<f n="BrandCode" v="7"/>
<f n="state" v="AK"/>
<f n="city" v="Fairbanks"/>
<f n="name" v="name2"/>

</v>
</searchresults>

Your help is greatly appreciated.

Postnext
Rahul PuttaguntaSubject: xml, xslt question
Author: Rahul Puttagunta
Date: 04 Oct 2006 12:54 PM
bump ....


I guess i just need the XSL transformation that THIS particular forum is doing for trimming the attribute spaces on my XML.

Thank you,
Rahul.

Postnext
James DurningSubject: xml, xslt question
Author: James Durning
Date: 05 Oct 2006 05:52 PM
Originally Posted: 05 Oct 2006 05:51 PM
<xsl:template match="*">
<xsl:copy>
<xsl:apply-templates select="node()"/>
</xsl:copy>
</xsl:template>

<xsl:template match="@*">
<xsl:attribute name="{name()}">
<xsl:value-of select="translate(.,' ','')
</xsl:attribute>
</xsl:template>

you could also use normalize-space()

Postnext
Rahul PuttaguntaSubject: xml, xslt question
Author: Rahul Puttagunta
Date: 06 Oct 2006 04:10 PM
Thank you, but the XSL you gave me look like they are two different XSL's . Also, one of the two xml's was not well formed. Can you help me out please?

Thank you,
Rahul.

Posttop
Rahul PuttaguntaSubject: xml, xslt question
Author: Rahul Puttagunta
Date: 09 Oct 2006 10:57 AM
My friend posted this in a google groups forum, and, somebody answered. Here is the solution:


<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:template match="/">
<xsl:apply-templates select="searchresults" mode="normalize"/>
</xsl:template>
<xsl:template match="node()" mode="normalize">
<xsl:copy >
<xsl:apply-templates select="@*" mode="normalize"/>
<xsl:apply-templates select="*" mode="normalize"/>
</xsl:copy>
</xsl:template>
<xsl:template match="@*" mode="normalize">
<xsl:attribute name="{name(.)}">
<xsl:value-of select="normalize-space(.)"/>
</xsl:attribute>
</xsl:template>

 
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.