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
Priya AnbulakshmiSubject: Identity Transformation in XSL !! Pleas help me..
Author: Priya Anbulakshmi
Date: 05 Feb 2007 05:52 PM
I have one xml like this..

<a>
<b>
<x1>CS<x1>
<x2>NY</x2>
</b>
<b>
<x1>MECH</x1>
<x2>FL</x2>
</b>
<c></c>
</a>

I need to convert this xml using XSLT using Identity Transformation like
<a>
<b>
<x1>Computer Science<x1>
<x2>New York</x2>
</b>
<b>
<x1>MECHANICAL</x1>
<x2>FLORIDA</x2>
</b>
<c></c>
</a>


Whenever i tried i used to get like below...
<a>
<b>
<x1>Computer Science<x1>
<x2>New York</x2>
</b>
<b>
<x1>Computer Science</x1>
<x2>New York</x2>
</b>
<c></c>
</a>

Could you please tell me how to do that ?

Postnext
Tony LavinioSubject: Identity Transformation in XSL !! Pleas help me..
Author: Tony Lavinio
Date: 06 Feb 2007 01:46 AM
1. It would help when you show us your XSLT, so we know what you've tried.
2. Please also include the version of Stylus Studio you are using.

Postnext
Priya AnbulakshmiSubject: Identity Transformation in XSL !! Pleas help me..
Author: Priya Anbulakshmi
Date: 06 Feb 2007 11:34 AM
I m using Stylus Studio XML Professional Edition.

This is my XSL i m trying...
<xsl:choose>
<xsl:when test="a/b='NY'">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:text>NEW YORK</xsl:text>
</xsl:copy>
</xsl:when>
<xsl:otherwise>
<xsl:copy>
<xsl:copy-of select="@*" />
<xsl:apply-templates mode="copy"/>
</xsl:copy>
</xsl:otherwise>

</xsl:choose>

Postnext
Tony LavinioSubject: Identity Transformation in XSL !! Pleas help me..
Author: Tony Lavinio
Date: 06 Feb 2007 11:41 AM
You will need to post the whole XSLT.
The problem is often in the parts you don't show.

Postnext
Priya AnbulakshmiSubject: Identity Transformation in XSL !! Pleas help me..
Author: Priya Anbulakshmi
Date: 06 Feb 2007 11:59 AM
Hi,
Thanks for your instant reply... Below is my full XSLT..

<?xml version="1.0" encoding="UTF-8"?>

<xsl:transform
version="1.1"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
<xsl:output method="xml" encoding="UTF-8" indent="yes"/>

<xsl:template match="*">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>

<xsl:template match="a/b/x1">
<xsl:choose>
<xsl:when test="a/b/x1='CS'">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:text>COMPUTER SCIENCE</xsl:text>
</xsl:copy>
</xsl:when>
<xsl:when test="a/b/x1='MECH'">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:text>MECHANICAL</xsl:text>
</xsl:copy>
</xsl:when>
<xsl:otherwise>
<xsl:copy>
<xsl:copy-of select="@*" />
<xsl:apply-templates mode="copy"/>
</xsl:copy>
</xsl:otherwise>

<xsl:template match="/a/b/x2">
<xsl:choose>
<xsl:when test="a/b/x2='NY'">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:text>NEW YORK</xsl:text>
</xsl:copy>
</xsl:when>
<xsl:when test="a/b/x2='FL'">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:text>FLORIDA</xsl:text>
</xsl:copy>
</xsl:when>
<xsl:otherwise>
<xsl:copy>
<xsl:copy-of select="@*" />
<xsl:apply-templates mode="copy"/>
</xsl:copy>
</xsl:otherwise>
</xsl:choose>
</xsl:template>

</xsl:transform>

Posttop
(Deleted User) Subject: Identity Transformation in XSL !! Pleas help me..
Author: (Deleted User)
Date: 07 Feb 2007 06:44 AM
Prya,
first of all, beware that the XSLT you pasted is not well-formed (the template for "a/b/x1" is missing the closing </xsl:choose></xsl:template>).

The error in your code is in the xsl:when instructions, where they test the full path "a/b/x1='CS'": being inside a template matching "a/b/x1" (or "a/b/x2") the context is already the x1 or x2 node, so you should change them to do <xsl:when test=".='CS'">, <xsl:when test=".='MECH'">, <xsl:when test=".='NY'">, <xsl:when test=".='FL'">.

Hope this helps,
Alberto

 
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.