Re: [xsl] Remove internal parsing and exclude one child

Subject: Re: [xsl] Remove internal parsing and exclude one child
From: "Charles O'Connor coconnor@xxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Tue, 16 May 2017 18:18:53 -0000
Thank you Graydon and Martin! These both work perfectly, and it's kind of neat
to see the rather different approaches to the same issue. I groped along each
path before asking for help.

Martin, regarding XSLT 1.0 and Saxon 9, I was mixing concerns. I'm using Saxon
on my own machine, but the environment where this might be used currently is
limited to 1.0.

Thanks,
Charles

-----Original Message-----
From: Graydon graydon@xxxxxxxxx
[mailto:xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx]
Sent: Tuesday, May 16, 2017 2:02 PM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re: [xsl] Remove internal parsing and exclude one child

On Tue, May 16, 2017 at 05:29:27PM -0000, Charles O'Connor
coconnor@xxxxxxxxxxxx scripsit:
> Using XSLT 1.0/Saxon9he
>
> I have this input
>
> <aff id="aff1"><label>1</label>Jet Propulsion Laboratory (JPL), 4800
> Oak Grove Dr Pasadena, CA <addr-line><postal-code>91109</postal-code>,
> <country>USA</country></addr-line></aff>
> <aff id="aff2"><label>2</label>SCRIPPS Institution of Oceanography,
> 9500 Gilman Drive, <institution>Dept 0230</institution>,
> <addr-line><city>La Jolla</city>, <state>CA</state>
> <postal-code>92093-0230</postal-code></addr-line>,
> <country>USA</country></aff>
>
> And would like to get the same back, without the internal parsing and
> excluding the contents of <label>, e.g.,
>
> <aff id="aff1">Jet Propulsion Laboratory (JPL), 4800 Oak Grove Dr
> Pasadena, CA 91109, USA</aff> <aff id="aff2">SCRIPPS Institution of
> Oceanography, 9500 Gilman Drive, Dept 0230, La Jolla, CA 92093-0230,
> USA</aff>

<xsl:template match="aff">
    <xsl:copy>
        <xsl:apply-templates select="@*" />
        <xsl:for-each
select="descendant-or-self::text()[not(parent::label)]">
             <xsl:value-of select="." />
        </xsl:for-each>
    </xsl:copy>
</xsl:template>

XSLT 1.0 makes this harder by having odd rules about only taking the first
text node; that select in a value-of doesn't work.

-- Graydon

Current Thread