Subject: [xsl] XSLT2: Grouping mixed content between opening and closing marker elements From: "Keith Burt keithburt66@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> Date: Sat, 15 Aug 2020 10:19:22 -0000 |
Good morning In my simplified example, I have self closing 'e' elements that have a tag attribute that denotes the start and end points of where style (in this case bold and italic) should be applied. I want to group the content within the start and end markers, and create a wrapper element based on the tag attribute. My XSLT skills are limited. Through trial and error, the following template groups the content I want between the start and end 'b' markers. <xsl:template match="*[@tag='b']"> <xsl:element name="{@tag}"> <xsl:apply-templates select="@*"/> <xsl:apply-templates select="following::node() except following::node()[@tag='/b'][1]/following::node()"/> </xsl:element> </xsl:template> But as this template is part of an identity transform, I'm getting duplicate content, so I need to suppress the following nodes that I have already grouped. This is the part that I am stuck on. Any guidance would be appreciated. *Input* <?xml version="1.0" encoding="UTF-8"?> <paragraph>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas facilisis diam ac mi molestie faucibus. <e tag="b"/>Nulla facilisi<e tag="/b"/>. Ut molestie metus arcu, ut vestibulum dolor dignissim ut. <e tag="b"/>Cras tempor tortor libero, <e tag="i"/>non pretium ipsum efficitur vitae. Nulla facilisi. Sed maximus varius purus, in egestas justo<e tag="/i"/>. Nam eleifend metus vel odio rutrum auctor<e tag="/b"/>. Proin scelerisque purus pellentesque, congue quam quis, interdum lectus. Fusce accumsan sapien non turpis scelerisque, vel efficitur ligula rhoncus.</paragraph> *Desired Output* <?xml version="1.0" encoding="UTF-8"?> <paragraph>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas facilisis diam ac mi molestie faucibus. <b>Nulla facilisi</b>. Ut molestie metus arcu, ut vestibulum dolor dignissim ut. <b>Cras tempor tortor libero, <i>non pretium ipsum efficitur vitae. Nulla facilisi. Sed maximus varius purus, in egestas justo</i>. Nam eleifend metus vel odio rutrum auctor</b>. Proin scelerisque purus pellentesque, congue quam quis, interdum lectus. Fusce accumsan sapien non turpis scelerisque, vel efficitur ligula rhoncus.</paragraph> Many thanks. -- Keith
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] problem with transforming, Mukul Gandhi gandhi. | Thread | Re: [xsl] XSLT2: Grouping mixed con, Martin Honnen martin |
Re: [xsl] problem with transforming, Michael Kay mike@xxx | Date | Re: [xsl] problem with transforming, Mukul Gandhi gandhi. |
Month |