[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: XML/XML Transformation - Please Help !!!.....
- From: Thushara Perera <thusharap@eurocenter.lk>
- To: "G. Ken Holman" <gkholman@CraneSoftwrights.com>,"XML-DEV (E-mail)" <xml-dev@lists.xml.org>
- Date: Mon, 30 Apr 2001 16:35:14 +0600
Hi
I have posted this in XSL list as well. BUT no one replied to me regarding
my question.
I am totally hopeless. Please tell me if you know how to do this.
Thanks
Thushara
-----Original Message-----
From: G. Ken Holman [mailto:gkholman@CraneSoftwrights.com]
Sent: Monday, April 30, 2001 3:53 PM
To: XML-DEV (E-mail)
Subject: Re: XML/XML Transformation - Please Help !!!.....
XSL, XSLT and XPath questions would be better posted to the following list:
http://www.mulberrytech.com/xsl/xsl-list
There are a number of subscribers who would enthusiastically respond to
such questions.
There is also an *excellent* FAQ at:
http://www.dpawson.co.uk
At 01/04/30 13:58 +0600, Thushara Perera wrote:
>Could someone PLEASE tell me how to do the XML to XML transformation as
>described below ?
>
>Part of my XML file is:
>..
>..
>..
> <URLADR>http:\\www.aaa.com</URLADR>
> <URLDESC>Homepage of aaa AS</URLDESC>
> <URLDESCLANGUAGE>en</URLDESCLANGUAGE>
> <URLDESC>Homepage of aaa AS NO</URLDESC>
> <URLDESCLANGUAGE>no</URLDESCLANGUAGE>
> <URLDESC>Homepage of aaa AS SE</URLDESC>
> <URLDESCLANGUAGE>se</URLDESCLANGUAGE>
>
> <URLADR>http:\\www.aaabbb.org</URLADR>
> <URLDESC>Demo of aaabbb.com</URLDESC>
> <URLDESCLANGUAGE>en</URLDESCLANGUAGE>
> <URLDESC>Demo of aaabbb.com NO</URLDESC>
> <URLDESCLANGUAGE>no</URLDESCLANGUAGE>
>..
>..
>..
>
>and I want to convert this to something like:
>..
>..
> <URLLIST>
> <URL>
> <URLADR><http://www.aaa.com>http://www.aaa.com</URLADR>
> <URLDESC xml:lang="en">Homepage of aaa AS></URLDESC>
> <URLDESC xml:lang="no">Homepage of aaa AS NO></URLDESC>
> <URLDESC xml:lang="se">Homepage of aaa AS SE></URLDESC>
> </URL>
> <URL>
> <URLADR><http://www.hubshop.org>http://www.aaabbb.org</URLADR>
> <URLDESC xml:lang="en">Demo of aaabbb.com></URLDESC>
> <URLDESC xml:lang="no">Demo of aaabbb.com NO></URLDESC>
> </URL>
> </URLLIST>
>..
>..
>
>Please tell me how to write the XSL file for this.
You are trying to convert a non-tree structure into a tree structure (at
the information level, it is of course a tree at the syntax level). This
requires you to "walk" the tree to find the information you need.
The code below will accomplish your desired result ... note that it acts on
each URL element using inherent tree-oriented XSLT, but then must walk the
tree, element node by element node, determining the content for the result
element.
I hope this helps.
...................... Ken
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output indent="yes"/>
<xsl:template match="/">
<URLLIST>
<xsl:for-each select="//URLADR">
<URL>
<xsl:copy-of select="."/>
<!--walk the tree along siblings until next URLADR found-->
<xsl:apply-templates select="following-sibling::*[1]"
mode="urldesc"/>
</URL>
</xsl:for-each>
</URLLIST>
</xsl:template>
<xsl:template match="URLDESC" mode="urldesc"> <!--add description to URL-->
<xsl:copy>
<xsl:attribute name="xml:lang">
<xsl:value-of
select="following-sibling::*[1][self::URLDESCLANGUAGE]"/>
</xsl:attribute>
<xsl:value-of select="."/>
</xsl:copy>
<xsl:apply-templates select="following-sibling::*[1]" mode="urldesc"/>
</xsl:template>
<xsl:template match="URLDESCLANGUAGE" mode="urldesc"> <!--value used-->
<xsl:apply-templates select="following-sibling::*[1]" mode="urldesc"/>
</xsl:template>
<xsl:template match="URL" mode="urldesc"/> <!--stop at next URL-->
<xsl:template match="*" mode="urldesc">
<xsl:message>
<xsl:text/>Unexpected: '<xsl:value-of select="name(.)"/>'<xsl:text/>
</xsl:message>
</xsl:template>
</xsl:stylesheet>
--
G. Ken Holman mailto:gkholman@CraneSoftwrights.com
Crane Softwrights Ltd. http://www.CraneSoftwrights.com/x/
Box 266, Kars, Ontario CANADA K0A-2E0 +1(613)489-0999 (Fax:-0995)
Web site: XSL/XML/DSSSL/SGML/OmniMark services, training, products.
Book: Practical Transformation Using XSLT and XPath ISBN 1-894049-06-3
Article: What is XSLT? http://www.xml.com/pub/2000/08/holman/index.html
Next public instructor-led training: 2001-05-01,05-14,05-15,05-16,
- 05-17,05-21,05-22,06-18,06-21,07-20,07-21,09-19
Training Blitz: 3-days XSLT/XPath, 2-days XSLFO in Ottawa 2001-06-18/22
------------------------------------------------------------------
The xml-dev list is sponsored by XML.org, an initiative of OASIS
<http://www.oasis-open.org>
The list archives are at http://lists.xml.org/archives/xml-dev/
To unsubscribe from this elist send a message with the single word
"unsubscribe" in the body to: xml-dev-request@lists.xml.org