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