 |
| 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
|
|
|
|

June 6th, 2012, 07:23 AM
|
|
Authorized User
|
|
Join Date: Jun 2012
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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>
|
|

June 6th, 2012, 07:34 AM
|
|
Friend of Wrox
|
|
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
|
|
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
|
|

June 6th, 2012, 07:38 AM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
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
|
|

June 6th, 2012, 08:36 AM
|
|
Authorized User
|
|
Join Date: Jun 2012
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
<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>
|
|

June 6th, 2012, 09:03 AM
|
|
Friend of Wrox
|
|
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
|
|
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
|
|

June 6th, 2012, 09:50 AM
|
|
Authorized User
|
|
Join Date: Jun 2012
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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>
|
|

June 6th, 2012, 09:56 AM
|
|
Friend of Wrox
|
|
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
|
|
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
|
|

June 6th, 2012, 10:11 AM
|
|
Authorized User
|
|
Join Date: Jun 2012
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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>
|
|

June 6th, 2012, 10:13 AM
|
|
Authorized User
|
|
Join Date: Jun 2012
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
sorry, i need it on XSLT 1.0
|
|
 |