Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 6th, 2012, 07:23 AM
Authorized User
 
Join Date: Jun 2012
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default need to add adjacent element(with their child nodes) in to single in XSLT

Input:::

<body>

<case>
Data
<b type=”cite”>
<c>
<d type=”acronym”/>
<e>
<f year=”year”>
</e>
Fjkalfjajf
</c>
</b>
</case>


<case>
Data2
<b type=”cite”>
<c>
<d type=”acronym”/>
<e>
<f year=”year”>
</e>
Fjkalfjajf
</c>
</b>


</case>
</body>


Expected output:: two case elements should make into one

<body>
<case>
Data
<b type=”cite”>
<c>
<d type=”acronym”/>
<e>
<f year=”year”>
</e>
Fjkalfjajf
</c>
</b>
Data2
<b type=”cite”>
<c>
<d type=”acronym”/>
<e>
<f year=”year”>
</e>
Fjkalfjajf
</c>
</b>

</case>
</body>
 
Old June 6th, 2012, 07:34 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

Please let us know whether you use an XSLT 2.0 processor like Saxon 9 or AltovaXML or an XSLT 1.0 processor.
And it would help us answer your question if you posted well-formed XML samples and marked them up with http://p2p.wrox.com/misc.php?do=bbcode#code
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
 
Old June 6th, 2012, 07:38 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

This particular example can be done using

[body]
<xsl:template match="body">
<case>
<xsl:copy-of select="case/child::node()"/>
</case>
</xsl:template>
[body]

It's possible this may not meet the general requirement, but since you've only shown us this one example, I have no way of knowing what the general requirement is.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
 
Old June 6th, 2012, 08:36 AM
Authorized User
 
Join Date: Jun 2012
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default

<body>
<head>
<info>
<case:parallelcite>(Case <ci:cite searchtype="CASE-REF"><ci:case><ci:caseref><ci:reporter value="C"/><ci:edition><ci:date year="1993"/></ci:edition><ci:page num="57"/></ci:caseref></ci:case><ci:content>C-57/93</ci:content></ci:cite>)</case:parallelcite>


<case:parallelcite>(Case <ci:cite searchtype="CASE-REF"><ci:case><ci:caseref><ci:reporter value="C"/><ci:edition><ci:date year="1993"/></ci:edition><ci:page num="128"/></ci:caseref></ci:case><ci:content>C-128/93</ci:content></ci:cite>)</case:parallelcite>
</info>
</head>
</body>

it should get it as

<body>
<head>
<info>
<case:parallelcite>
(Case <ci:cite searchtype="CASE-REF"><ci:case><ci:caseref><ci:reporter value="C"/><ci:edition><ci:date year="1993"/></ci:edition><ci:page num="57"/></ci:caseref></ci:case><ci:content>C-57/93</ci:content></ci:cite>)

(Case <ci:cite searchtype="CASE-REF"><ci:case><ci:caseref><ci:reporter value="C"/><ci:edition><ci:date year="1993"/></ci:edition><ci:page num="128"/></ci:caseref></ci:case><ci:content>C-128/93</ci:content></ci:cite>)
</case:parallelcite>
</info>
</head>
</body>
 
Old June 6th, 2012, 09:03 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

Do you want to join all "case:parallelcite" child elements of the "info" element? Or pairs of two?
Can there be other child elements of the "info" element the stylesheet needs to copy as well?
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
 
Old June 6th, 2012, 09:50 AM
Authorized User
 
Join Date: Jun 2012
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default

info got some other elements as well, case:parallelcite is one in it..

just case:parallecite element should pair to one as

<body>
<head>
<info>
<case:parallelcite>
(Case <ci:cite searchtype="CASE-REF"><ci:case><ci:caseref><ci:reporter value="C"/><ci:edition><ci:date year="1993"/></ci:edition><ci:page num="57"/></ci:caseref></ci:case><ci:content>C-57/93</ci:content></ci:cite>)

(Case <ci:cite searchtype="CASE-REF"><ci:case><ci:caseref><ci:reporter value="C"/><ci:edition><ci:date year="1993"/></ci:edition><ci:page num="128"/></ci:caseref></ci:case><ci:content>C-128/93</ci:content></ci:cite>)
</case:parallelcite>
</info>
</head>
</body>
 
Old June 6th, 2012, 09:56 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

Please tell us whether you need an XSLT 2.0 or 1.0 solution? It looks to me as XSLT 2.0 could do it easily with for-each-group select="*" group-adjacent="boolean(self::case:parallelcite)".
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
 
Old June 6th, 2012, 10:11 AM
Authorized User
 
Join Date: Jun 2012
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default

this is my code, i know it doing nothing help me to make changes please

<xsl:variable name="prev" select="(./preceding-sibling::*)[1]"/>
<xsl:variable name="next" select="(./following-sibling::*)[1]"/>

<xsl:template match="case:parallelcite">
<xsl:choose>
<xsl:when test="name($next) = 'case:parallelcite'">
<case:parallelcite>
<xsl:apply-templates select="."/>
<xsl:apply-templates select="following-sibling::case:parallelcite"/>
</case:parallelcite>
</xsl:when>
<xsl:when test="name($prev) = 'case:parallelcite'">
</xsl:when>
<xsl:otherwise>
<case:parallelcite>
<xsl:apply-templates/>
</case:parallelcite>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
 
Old June 6th, 2012, 10:13 AM
Authorized User
 
Join Date: Jun 2012
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default

sorry, i need it on XSLT 1.0





Similar Threads
Thread Thread Starter Forum Replies Last Post
Add name to element with XSLT mroosendaal XSLT 1 February 3rd, 2012 06:30 AM
Appending child nodes to a RDF/OWL file using xslt sesath XSLT 2 May 10th, 2007 04:37 AM
XSLT for Variable Child Nodes jlagedo XSLT 2 September 10th, 2006 03:00 AM
counting child nodes Tomi XSLT 1 September 6th, 2006 03:26 AM
replace single child with value Kabe Classic ASP XML 1 April 14th, 2004 09:11 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.