Re: [xsl] How to remove outer tag if present in XSLT

Subject: Re: [xsl] How to remove outer tag if present in XSLT
From: "Dimitre Novatchev dnovatchev@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Fri, 17 Mar 2023 22:50:06 -0000
Matt,

I would have told you exactly what Martin Honnen told you:

Change in the solution that I provided earlier this:

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

to this:

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


But, as it often happens on this mailing list and other Q&A sites such as
Stack Overflow, we could be witnessing a lengthy saga where the exact
problem is revealed only in the last episode.

Please, be careful and more precise in the future and be aware that not
everyone has the time and interest to follow through all the episodes of
the saga.

Paying more attention to the definition of the problem has great and
unexpected added benefits, such as the OP suddenly understanding the
**real** problem and discovering its solution by themselves.

And a little bit of education wouldn't hurt either. There are good
resources such as Pluralsight courses, individualized training (like the
one provided by my friend Liam Quin), etc.

As they say, bIf you give a man a fish, you feed him for a day. If you
teach a man to fish, you feed him for a lifetime.b

I am fed up with giving just a single fish to people although they could
learn from me, more or less well, how to fish.

Thanks,
Dimitre


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

>
> Ungroup (remove) the outer <p> if it is the only element that is a child
> of the arbitrary outer node (and is a <p> node)..
>
> So a <div>
> ...
> ...
> </div>
> Would not unwrap, since it's a "<div>" and not a "<p>"
>
>
> Thanks,
> Matt V.
> >
> ------------------------------
> *From:* Chris Papademetrious christopher.papademetrious@xxxxxxxxxxxx <
> xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
> *Sent:* Friday, March 17, 2023 1:01 PM
> *To:* xsl-list@xxxxxxxxxxxxxxxxxxxxxx <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
> *Subject:* Re: [xsl] How to remove outer tag if present in XSLT
>
>
> Hi Matt,
>
>
>
> What are the precise conditions in which you want to ungroup the <p>?
>
>
>
> Is it when all of the following are true:
>
>
>
>    - The element is a <p> element.
>    - The <p> element is the only child of its parent (it stands alone).
>    - The <p> element contains one or more child <p> elements.
>    - The <p> element contains no non-<p> elements.
>
>
>
>    - Chris
>
>
>
> *From:* Matt Van Voorhies mvanvoorhies@xxxxxxxxxxx <
> xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
> *Sent:* Friday, March 17, 2023 12:56 PM
> *To:* xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> *Subject:* [xsl] How to remove outer tag if present in XSLT
>
>
>
>
>
>                 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
>
<https://urldefense.com/v3/__http:/www.mulberrytech.com/xsl/xsl-list__;!!A4F2
R9G_pg!f_qbvL1lxWOiZkRI0MumM1kH5KnOex4dlaYXYl62f4FzOdI62eejmsROCcOtdPJgF-tbZj
HczucMh-Dl7QrZrXNxWEcJ2NuFhCn7c_DukKs7FRSJCoPy$>
>
> EasyUnsubscribe
>
<https://urldefense.com/v3/__http:/lists.mulberrytech.com/unsub/xsl-list/3380
743__;!!A4F2R9G_pg!f_qbvL1lxWOiZkRI0MumM1kH5KnOex4dlaYXYl62f4FzOdI62eejmsROCc
OtdPJgF-tbZjHczucMh-Dl7QrZrXNxWEcJ2NuFhCn7c_DukKs7FTtFsvdm$>
> (by email)
> XSL-List info and archive <http://www.mulberrytech.com/xsl/xsl-list>
> EasyUnsubscribe <http://lists.mulberrytech.com/unsub/xsl-list/3506713> (by
> email)
> 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