Re: [xsl] Getting all the text of an element, except for one type

Subject: Re: [xsl] Getting all the text of an element, except for one type
From: "Bauman, Syd s.bauman@xxxxxxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Fri, 9 Feb 2024 14:05:39 -0000
There are many ways to skin this cat. Here is one:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
version="3.0">

  <xsl:output indent="yes"/>
  <xsl:mode on-no-match="shallow-copy"/>

  <xsl:template match="/pub">
    <xsl:copy>
      <xsl:apply-templates select="section/title"/>
    </xsl:copy>
  </xsl:template>

  <xsl:template match="title">
    <entry><xsl:apply-templates/></entry>
  </xsl:template>

  <xsl:template match="title/data"/>

</xsl:stylesheet>


________________________________


Hi All. Here is my input:



<?xml version="1.0" encoding="UTF-8"?>

<pub>

    <section>

        <title>This is my clever title with <ph>a phrase</ph> and some

            data.<data>12345</data></title>

        <p>A plain paragraph.</p>

    </section>

    <section>

        <title>Another title without any children.</title>

        <p>Another plain paragraph.</p>

    </section>

</pub>



I want to get all of the text from the <title> elements are its children,
except for <data> elements:



<?xml version="1.0" encoding="UTF-8"?>

<pub>

   <entry>This is my clever title with a phrase and some data. </entry>

   <entry>Another title without any children.</entry>

</pub>



Here is my stylesheet but I am missing something in my understanding. Thanks
in advance for your help.



<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";

    xmlns:xs="http://www.w3.org/2001/XMLSchema";

    xmlns:math="http://www.w3.org/2005/xpath-functions/math";

    exclude-result-prefixes="xs math"

    version="3.0" expand-text="yes">



    <xsl:output indent="yes"/>



    <xsl:template match="/pub">

        <xsl:copy>

            <xsl:apply-templates select="section"/>

        </xsl:copy>

    </xsl:template>



    <xsl:template match="section">

        <entry><xsl:value-of select="title/descendant-or-self::* except
data"/></entry>

    </xsl:template>



</xsl:stylesheet>

Current Thread