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

Re: How to remove outer tag if present in XSLT

Subject: Re: How to remove outer tag if present in XSLT
From: "Dimitre Novatchev dnovatchev@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Fri, 17 Mar 2023 17:26:17 -0000
Re:  How to remove outer tag if present in XSLT
A simple XSLT 1.0 solution (using even Saxon 6.5.3 is OK :) ):

<xsl:stylesheet version="1.0" xmlns:xsl="
http://www.w3.org/1999/XSL/Transform">
 <xsl:output omit-xml-declaration="yes" indent="yes"/>
 <xsl:strip-space elements="*"/>

  <xsl:template match="node()|@*">
    <xsl:copy>
      <xsl:apply-templates select="node()|@*"/>
    </xsl:copy>
  </xsl:template>

  <xsl:template
match="arbitrary-outer-tag-thats-valid/*[1][not(following-sibling::*)]">
     <xsl:apply-templates/>
  </xsl:template>
</xsl:stylesheet>

Thanks,
Dimitre

On Fri, Mar 17, 2023 at 9:55b/AM Matt Van Voorhies mvanvoorhies@xxxxxxxxxxx
<
xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:

>
>
>                Hi folks,
>
>
>
>                               I have a hopefully simple question that I
> was unable to find a good answer for.  Ibm trying to convert some code we
> have that manipulates an XML structure (transforming to HTML output) and
> move it into the XSLT transform.
>
>
>
>                               Problem:  Given a specific XML tag, I need
> to remove the bcontaining paragraphb but only if itbs a single
containing
> paragraph tag.  Parsing using .NET Saxon 10.6 for transform.
>
>
>
>                               So for example, if I have the following XML
> structure b
>
>
>
>                               <arbitrary-outer-tag-thats-valid>
>                                     <p>Some content, probably a bunch of
> internal tags like H1, H2, LI, DIV, etc.  </p>
>                                     <p>More content, again, may have more
> stuff in it like an <p>Internal paragraph</p></p>
>                                     <p>stuff3</p>
>                         </ arbitrary-outer-tag-thats-valid >
>
>
>
>                         Running through the transform would produce:
>
>
>
>                         <arbitrary-outer-tag-thats-valid>
>                                     <p>Some content, probably a bunch of
> internal tags like H1, H2, LI, DIV, etc.  </p>
>                                     <p>More content, again, may have more
> stuff in it like an <p>Internal paragraph</p></p>
>                                     <p>stuff3</p>
>                         </ arbitrary-outer-tag-thats-valid >
>
>
>
>                         Since there is *not* an outer/containing
> paragraph tag.
>
>
>
>                         However, if the input was b
>
>
>
>                         <arbitrary-outer-tag-thats-valid>
>
> *<p>*
>                         <p>Some content, probably a bunch of internal
> tags like H1, H2, LI, DIV, etc.  </p>
>                         <p>More content, again, may have more stuff in it
> like an <p>Internal paragraph</p></p>
>                         <p>stuff3</p>
>
> *</p>*
> </ arbitrary-outer-tag-thats-valid >
>
>
>
>                Running through the transform would produce:
>
>
>
>                <arbitrary-outer-tag-thats-valid>
>                                     <p>Some content, probably a bunch of
> internal tags like H1, H2, LI, DIV, etc.  </p>
>                                     <p>More content, again, may have more
> stuff in it like an <p>Internal paragraph</p></p>
>                                     <p>stuff3</p>
>                         </ arbitrary-outer-tag-thats-valid >
>
>
>
>             Where the single, containing <p> tag was removed, but
> everything inside of it was retained exactly as it was.
>
>
>
>             Could someone help?
>
>
>
>             Thanks,
>
>                         Matt Van Voorhies
>
>                         mvanvoorhies@xxxxxxxxxxx
>
>
>
>
>
>
>
> XSL-List info and archive <http://www.mulberrytech.com/xsl/xsl-list>
> EasyUnsubscribe <http://lists.mulberrytech.com/unsub/xsl-list/782854> (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.