[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Aw:  How to collect the content of the inline sibl

Subject: Re: Aw:  How to collect the content of the inline siblings into a single element.
From: "Don Smith dsmith_lockesmith@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Sat, 28 Dec 2024 06:13:38 -0000
Re: Aw:  How to collect the content of the  inline sibl
 Hello Rajagopal,
Well done sharing both the source XML and desired output; that makes
everything easier.
As usual, Martin has provided the solution. However, my own tests indicate
that the mixed content involved adds additional complexity (no surprise
there). So I find that additionally are required (1) a strip space instruction
and (2) an additional processing mode for the <strong> element. Here's the
coded solution I have (I expect the better developers on the list will update
with a more elegant solution):
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"B  B 
xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="xs"
version="2.0">
B  B  B <xsl:strip-space elements="*"/>
B  B  <xsl:template match="*">B  B  B  B  <xsl:copy>B  B  B  B  B  B 
<xsl:copy-of select="@*"/>B  B  B  B  B  B  <xsl:apply-templates/>B  B  B  B 
</xsl:copy>B  B  </xsl:template>
B  B  <xsl:template match="div[child::strong]">B  B  B  B  <xsl:copy>B  B  B 
B  B  B  <xsl:copy-of select="@*"/>B  B  B  B  B  B  <xsl:for-each-group
select="node()" group-adjacent="boolean(self::strong)">B  B  B  B  B  B  B  B 
<xsl:choose>B  B  B  B  B  B  B  B  B  B  <xsl:when
test="current-grouping-key() = true()">B  B  B  B  B  B  B  B  B  B  B  B 
<strong>B  B  B  B  B  B  B  B  B  B  B  B  B  B  <xsl:apply-templates
select="current-group()" mode="nospace"/>B  B  B  B  B  B  B  B  B  B  B  B 
</strong>B  B  B  B  B  B  B  B  B  B  </xsl:when>B  B  B  B  B  B  B  B  B 
B  <xsl:otherwise>B  B  B  B  B  B  B  B  B  B  B  B  <xsl:apply-templates
select="."/>B  B  B  B  B  B  B  B  B  B  </xsl:otherwise>B  B  B  B  B  B  B 
B  </xsl:choose>B  B  B  B  B  B  </xsl:for-each-group>B  B  B  B 
</xsl:copy>B  B  </xsl:template>
B  B  <xsl:template match="strong" mode="nospace">B  B  B  B  <xsl:value-of
select="."/>B  B  </xsl:template>
</xsl:stylesheet>





B 
    On Friday, December 27, 2024 at 11:03:45 PM CST, Martin Honnen
martin.honnen@xxxxxx <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:

 With XSLT 2 or higher, in a template matching "*[strong]", use eg
<xsl:for-each-group select="*" group-adjacent="boolean(self::strong)">, check
the current-grouping-key() inside with xsl:choose/when to output a single
strong element if it is true and populate by processing the child nodes of the
current-group(), otherwise just process the current group, with the identity
transformation set up

--
Gesendet mit der GMX Mail App

Am 28.12.24, 05:26 schrieb "Rajagopal CV cvr3@xxxxxxxxxxxxxxxx"
<xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>:

Kindly assist me with an XSL code needed to generate the output I have shared
below.

Thanks,

Rajagopal




Input XMLB 

<?xml version="1.0"?>B 

<root>B 

B  B  <content>B 

B  B  B  B  <p>Some text before</p>B 

B  B  B  B  <div>B 

B  B  B  B  B  B  <strong>First</strong>B 

B  B  B  B  B  B  <strong>Second</strong>B 

B  B  B  B  B </div>B 

B  B  B  B  B <div>some texts </div>B 

B  B  B  B  B  <div>Other textB B 

B  B  B  B  B  B  B  B  <strong>ABC</strong>B B 

B  B  B  B  B  B  B  B  <strong>DEF</strong>B B 

B  B  B  B  B  B  B  B  <strong>IJK</strong>B 

B  B  B  B  B  B  B  B  B some text nodeaB 

B  B  B  B  B  B  B  B  <strong>JJJJ</strong>B 

B  B  B  B  B  B  B  B  <strong>HHH</strong>B 

B  B  B  B  B  B  </div>

B  B  B  B  B  B  <div>B 

B  B  B  B  B  B  B  B  <strong>First</strong>B 

B  B  B  B  B  B  B  B  <strong>Second</strong>B 

B  B  B  B  B  B </div>B 

B  B  B  B  </content>B 

</root>B 




I want the followingB output. I want to flatten out the <strong> element.B 




<?xml version="1.0"?>B 

<root>B 

B  B  <content>B 

B  B  B  B  <p>Some text before</p>B 

B  B  B  B  <div>B 

B  B  B  B  B  B  <strong>FirstSecond</strong>B 

B  B  B  B  B </div>B 

B  B  B  B  B <div>some texts </div>B 

B  B  B  B  B  <div>Other text B 

B  B  B  B  B  B  B  B  <strong>ABCDEFIJK</strong>B 

B  B  B  B  B  B  B  B  B some text nodesB 

B  B  B  B  B  B  B  B  <strong>JJJJHHH</strong>B 

B  B  B  B  B  B  </div>

B  B  B  B  B  B  <div>B 

B  B  B  B  B  B  B  B  <strong>FirstSecond</strong>B 

B  B  B  B  B  B </div>B 

B  B  B  B  </content>B 

</root>
XSL-List info and archiveEasyUnsubscribe(by email)
XSL-List info and archiveEasyUnsubscribe(by email)

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.