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: Sat, 18 Mar 2023 01:18:11 -0000
Dear Wendell,

> Hi Dimitre and XSL-List,
>
> It isn't altogether fair to be critical if stated requirements change, is
it? In the spirit of figuring things out?

Agreed, but don't things change all the time? :)

This is what makes valuable the understanding and knowledge of the things
that remain common and unchanged, the rules and laws in every science and
discipline.

If one doesn't strive to explore and acquire these and doesn't have the
feeling of constantly getting deeper, then this sounds like a lost
opportunity to grow...

Isn't this the base for our evergoing education and development, and
probably the most permanent and unchanging goal?

Just saying, and not in the mood to argue :)

Have a nice weekend!

Thanks,
Dimitre

On Fri, Mar 17, 2023 at 5:26b/PM Wendell Piez wapiez@xxxxxxxxxxxxxxx <
xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:

> Hi Dimitre and XSL-List,
>
> It isn't altogether fair to be critical if stated requirements change, is
> it? In the spirit of figuring things out?
>
> For example, it is possible that this might (also) work for the OP:
>
> <xsl:template match="p[p]">
>   <xsl:apply-templates/>
> </xsl:template>
>
> ... plus identity (copy) logic.
>
> But we don't know that. Because it's not a solution to the problem as
> stated, but to another problem overlapping it, which may or may not align
> with the actual use case. I might not even mention this ordinarily, due to
> risks of mis-fitting. Details matter! Here, I'm making a little point.
>
> This is normal. We figure things out as we go along.
>
> Cheers, Wendell
>
>
> On Fri, Mar 17, 2023 at 6:50b/PM Dimitre Novatchev dnovatchev@xxxxxxxxx <
> xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:
>
>> 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)
>>>
>>
>>
>> XSL-List info and archive <http://www.mulberrytech.com/xsl/xsl-list>
>> EasyUnsubscribe <http://lists.mulberrytech.com/unsub/xsl-list/174322> (by
>> email)
>>
>
>
> --
> ...Wendell Piez... ...wendell -at- nist -dot- gov...
> ...wendellpiez.com... ...pellucidliterature.org... ...pausepress.org...
> ...github.com/wendellpiez... ...gitlab.coko.foundation/wendell...
> XSL-List info and archive <http://www.mulberrytech.com/xsl/xsl-list>
> EasyUnsubscribe <http://lists.mulberrytech.com/unsub/xsl-list/782854> (by
> email <>)
>


--
Cheers,
Dimitre Novatchev
---------------------------------------
Truly great madness cannot be achieved without significant intelligence.
---------------------------------------
To invent, you need a good imagination and a pile of junk
-------------------------------------
Never fight an inanimate object
-------------------------------------
To avoid situations in which you might make mistakes may be the
biggest mistake of all
------------------------------------
Quality means doing it right when no one is looking.
-------------------------------------
You've achieved success in your field when you don't know whether what
you're doing is work or play
-------------------------------------
To achieve the impossible dream, try going to sleep.
-------------------------------------
Facts do not cease to exist because they are ignored.
-------------------------------------
Typing monkeys will write all Shakespeare's works in 200yrs.Will they write
all patents, too? :)
-------------------------------------
Sanity is madness put to good use.
-------------------------------------
I finally figured out the only reason to be alive is to enjoy it.

Current Thread