473,396 Members | 1,786 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Help needed to write an XSL - XML to XML transformation

Hi,

I want to change :

<?xml version="1.0" ?>
<nplbiblio >
<document status="U" creadate="19990410">
<xp>000000001</xp>
<doctype>JOURN-ART</doctype>
<prdate>19880901</prdate>
<ord>19880901</ord>
<titles>
<title>MORPHOLOGY OF NI/GAAS SURFACES</title>
</titles>
<author>SINHA M P, MAHAPATRA S</author>
<supplier>MIGRATION</supplier>
<attribs>
<attrib name="nr_hostdoc">5</attrib>
<attrib name="pg_from_hostdoc">19-21</attrib>
<attrib name="vol_hostdoc">19</attrib>

</attribs>
<publication>
<irn>
<issn>0026-2692</issn>
</irn>
</document>

<document status="U" creadate="19990410">
<xp>000000002</xp>
<doctype>JOURN-ART</doctype>
<prdate>19880901</prdate>
<ord>19880901</ord>
<titles>
<title>GRAFT COPOLYMERIZATION OF METHYL METHACRYLATE ON POLY (VINYL CHLORIDE).</title>
</titles>
<author>PREMAMOY GHOSH, ARABINDA SHEKHAR BHATTACHARYYA, SOMNATH MAITRA.</author>
<supplier>MIGRATION</supplier>
<attribs>
<attrib name="pg_from_hostdoc">135 - 148</attrib>
<attrib name="vol_hostdoc">162</attrib>

</attribs>
<publication>
<irn>
<issn>0003-3146</issn>
</irn>
</document>

</nplbiblio>


into :

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE nplbiblio SYSTEM "npl-entities.dtd">
<nplbiblio xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:npl="http://www.epo.org/npl" xsi:noNamespaceSchemaLocation="npldoc v2.0.xsd" rundate="20080123">
<document status="n" creadate="20080123">
<xp>000000001</xp>
<doctype>JOURN-ART</doctype>
<prdate>19880901</prdate>
<xp>000000001</xp>
<author>SINHA M P, MAHAPATRA S</author>
<supplier>MIGRATION</supplier>
<title>MORPHOLOGY OF NI/GAAS SURFACES</title>
<isbn/>
<issn>0026-2692</issn>
<first_page>19-21</first_page>
<issue>5</issue>
<volume>19</volume>

</document>
<document status="n" creadate="20080123">
<xp>000000002</xp>
<doctype>JOURN-ART</doctype>
<prdate>19880901</prdate>
<xp>000000002</xp>
<author>PREMAMOY GHOSH, ARABINDA SHEKHAR BHATTACHARYYA, SOMNATH MAITRA.</author>
<supplier>MIGRATION</supplier>
<title>GRAFT COPOLYMERIZATION OF METHYL METHACRYLATE ON POLY (VINYL CHLORIDE).</title>
<isbn/>
<issn>0003-3146</issn>
<first_page>135-148</first_page>
<volume>162</volume>

</document>
</nplbiblio>


I have written this XLS which works at 95%:

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:npl="http://www.epo.org/npl" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<xsl:output method="xml" doctype-system="npl-entities.dtd"/>

<xsl:key name = "kkk" match = "attribs/attrib" use = "@name" />
<xsl:template match="/">

<nplbiblio>
<xsl:attribute name="xsi:noNamespaceSchemaLocation">npldoc v2.0.xsd</xsl:attribute>
<xsl:attribute name="rundate">20080123</xsl:attribute>

<xsl:for-each select="nplbiblio/document">

<document status="n">
<xsl:attribute name="creadate">20080123</xsl:attribute>
<xsl:copy-of select="xp"/>
<xsl:copy-of select="doctype"/>
<xsl:copy-of select="prdate"/>
<xsl:copy-of select="xp"/>
<xsl:copy-of select="author"/>
<xsl:copy-of select="supplier"/>

<title>
<xsl:value-of select="titles/title"/>
</title>

<isbn>
<xsl:value-of select="publication/irn/isbn"/>
</isbn>

<issn>
<xsl:value-of select="publication/irn/issn"/>
</issn>

<first_page>
<xsl:value-of select = "key('kkk','pg_from_hostdoc')" />
</first_page>

<issue>
<xsl:value-of select = "key('kkk','nr_hostdoc')" />
</issue>

<volume>
<xsl:value-of select = "key('kkk','vol_hostdoc')" />
</volume>

</document>
</xsl:for-each>
</nplbiblio>
</xsl:template>
</xsl:stylesheet>


The only problem with the output is that the values of 'pg_from_hosdoc' , 'nr_hostdoc' and 'vol_hostdoc' are taken from the first record and repeats on the next record :

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE nplbiblio SYSTEM "npl-entities.dtd">
<nplbiblio xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:npl="http://www.epo.org/npl" xsi:noNamespaceSchemaLocation="npldoc v2.0.xsd" rundate="20080123">
<document status="n" creadate="20080123">
<xp>000000001</xp>
<doctype>JOURN-ART</doctype>
<prdate>19880901</prdate>
<xp>000000001</xp>
<author>SINHA M P, MAHAPATRA S</author>
<supplier>MIGRATION</supplier>
<title>MORPHOLOGY OF NI/GAAS SURFACES</title>
<isbn/>
<issn>0026-2692</issn>
<first_page>19-21</first_page>
<issue>5</issue>
<volume>19</volume>

</document>
<document status="n" creadate="20080123">
<xp>000000002</xp>
<doctype>JOURN-ART</doctype>
<prdate>19880901</prdate>
<xp>000000002</xp>
<author>PREMAMOY GHOSH, ARABINDA SHEKHAR BHATTACHARYYA, SOMNATH MAITRA.</author>
<supplier>MIGRATION</supplier>
<title>GRAFT COPOLYMERIZATION OF METHYL METHACRYLATE ON POLY (VINYL CHLORIDE).</title>
<isbn/>
<issn>0003-3146</issn>
<first_page>19-21</first_page>
<issue>5</issue>

<volume>19</volume>
</document>
</nplbiblio>
Jun 30 '08 #1
2 1994
jkmyoung
2,057 Expert 2GB
2 Possible ways:
1. Change your key such that it takes something unique form the document element containing the attribs.

eg:
<xsl:key name = "kkk" match = "attribs/attrib" use = "concat(..\preceding-sibling::xp,'-',@name)" />

Other work required when using the keys.
-----

2. Change the xpaths eg:
<first_page>
<xsl:value-of select = "attribs/attrib[@name='pg_from_hostdoc']" />
</first_page>

I think the 2nd way is much easier.
Jul 2 '08 #2
Hi ,

Thanks for your suggestion .

After some long trial and errors, I finally found the right XSL code :

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:npl="http://www.epo.org/npl" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<xsl:output method="xml" doctype-system="npl-entities.dtd"/>

<xsl:template match = "/" >

<nplbiblio>
<xsl:attribute name="xsi:noNamespaceSchemaLocation">npldoc v2.0.xsd</xsl:attribute>
<xsl:attribute name="rundate">20080123</xsl:attribute>

<xsl:for-each select="nplbiblio/document">


<document status="n">
<xsl:attribute name="creadate">20080123</xsl:attribute>
<xsl:copy-of select="xp"/>
<xsl:copy-of select="doctype"/>
<xsl:copy-of select="prdate"/>
<xsl:copy-of select="xp"/>
<xsl:copy-of select="author"/>
<xsl:copy-of select="supplier"/>

<title>
<xsl:value-of select="titles/title"/>
</title>

<isbn>
<xsl:value-of select="publication/irn/isbn"/>
</isbn>

<issn>
<xsl:value-of select="publication/irn/issn"/>
</issn>


<first_page>
<xsl:value-of select="attribs/attrib[@name='pg_from_hostdoc']"/>
</first_page>

<issue>
<xsl:value-of select="attribs/attrib[@name='nr_hostdoc']"/>
</issue>

<volume>
<xsl:value-of select="attribs/attrib[@name='vol_hostdoc']"/>
</volume>


</document>
</xsl:for-each>
</nplbiblio>
</xsl:template>

</xsl:stylesheet>

It works perfect !!

Thanks again
Jul 8 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Jack Smith | last post by:
Help needed on this question. Any help is appreciated. Thanks in advance. Given a binary string (i.e. a finite sequence of 0's and 1's) we choose any two digit substring 01 and replace it by a...
6
by: Pete | last post by:
I am just getting to grips with XML and I was wondering if you could help me with something that no-one seems able or willing to help with.. I have an XSLT file which should be transforming a...
1
by: Mark Tranchant | last post by:
I'm struggling to find a way to achieve the following transformation: <x a="1" b="2" c="3" ... /> into <y b="2" c="3" ... > <z a="1" /> </y> In other words, I want to pull out a specific...
2
by: A. Wiebenga | last post by:
Hi all! I am currently involved in a project in which I am supposed to write a XSLT-transformation sheet for some XML data. I will outline the situation first: I've got one large XML file...
40
by: Peter Row | last post by:
Hi all, Here is my problem: I have a SQL Server 2000 DB with various NVarChar, NText fields in its tables. For some stupid reason the data was inserted into these fields in UTF8 encoding. ...
5
by: Jeff Greenberg | last post by:
Not an experienced c++ programmer here and I've gotten myself a bit stuck. I'm trying to implement a class lib and I've run into a sticky problem that I can't solve. I'd appreciate any help that I...
22
by: Rafia Tapia | last post by:
Hi all This is what I have in mind and I will appreciate any suggestions. I am trying to create a xml help system for my application. The schema of the xml file will be <helpsystem> <help...
3
by: Stephen Sprunk | last post by:
On a project I'm working on, I ran across the following macros: /* assume s is struct stream *, s->p is char, v is unit16_t or uint32_t */ #define in_uint16_le(s,v) { v = *((s)->p++); v +=...
4
by: Jeff Higgins | last post by:
Hi, will someone show me how to write a transformation to obtain the desired output from the following input xml? Any help will be greatly appreciated. Thanks. Jeff Higgins Input xml:
5
by: barnetod | last post by:
I am trying to open a text file designated by the user. Then I want to change all lower case values to capital letters. Then write file. I am stuck and can not change the characters or am...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.