Re: [xsl] Fwd: Selecting First Child of Ancestor using Xpath

Subject: Re: [xsl] Fwd: Selecting First Child of Ancestor using Xpath
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxx>
Date: Wed, 20 Nov 2013 10:35:46 -0500
Hi Nathan,

As in XSLT 1.0, test="../../c04[1]" will test for the existencee of a
c04 inside the grandparent. Since you are inside a c04, this will
always be true.

You probably want something like "empty(../preceding-sibling::c04)"

But I might go to a little more trouble to make my logic explicit:

<xsl:template match="c04">
  <!-- binding a variable to a Boolean value capturing your test -->
 <xsl:variable name="c04-is-first" select="empty(preceding-sibling::c04)"/>
  <xsl:for-each select="did">
    <xsl:if test="$c04-is-first">...

I will forego the rant on why EAD is so much easier with plain 'c'
than it is with numbered components. So much easier that one is
usually rewarded by a pre-process that converts numbered components
into unnumbered ones....

Cheers, Wendell
Wendell Piez |
XML | XSLT | electronic publishing
Eat Your Vegetables

On Wed, Nov 20, 2013 at 10:12 AM, Nathan Tallman <ntallman@xxxxxxxxx> wrote:
> I have the following xml:
>                <c03 level="otherlevel" otherlevel="subsubseries"
> id="seriesB2ii">
>                   <did>
>                      <unittitle>Section ii. Subject Files</unittitle>
>                      <unitdate era="ce"
> calendar="gregorian">1937-1958</unitdate>
>                   </did>
>                   <scopecontent>
>                      <p>Scope and Content Note: Includes file on
> Jewish organizations, annual
>                         meetings, anti-discrimination and legislation,
> Commentary newsletter,
>                         Emergency Committee, foreign affairs, human
> and civil rights, Israel, joint
>                         defense appeal, Palestine immigration and
> platform, peace, and the American
>                         Jewish tercentenary.</p>
>                   </scopecontent>
>                   <arrangement>
>                      <p>Arrangement Note: Arranged alphabetically.</p>
>                   </arrangement>
>                   <c04 level="file">
>                      <did>
>                         <container type="Box">B7</container>
>                         <container type="Folder">30</container>
>                         <unittitle>Administrative Committee</unittitle>
>                         <unitdate era="ce"
> calendar="gregorian">1943-1944</unitdate>
>                      </did>
>                   </c04>
>                   <c04 level="file">
>                      <did>
>                         <container type="Box">B7</container>
>                         <container type="Folder">31</container>
>                         <unittitle>American Council for Judaism</unittitle>
>                         <unitdate era="ce" calendar="gregorian">1950</unitdate>
>                      </did>
>                   </c04>
>                   <c04 level="file">
>                      <did>
>                         <container type="Box">B7</container>
>                         <container type="Folder">32</container>
>                         <unittitle>American Jewish Conference</unittitle>
>                         <unitdate era="ce"
> calendar="gregorian">January - May 1943</unitdate>
>                      </did>
>                   </c04>
> I'm working on a template that matches on c04, then has an
> xsl:for-each for the did (so did is m context node). I am transforming
> this into an HTML table.
> I'd like to do an xsl:coose/when to test for the first c04 child of
> c03, so I can add table headers. As this is processing all dids I need
> the test to specifically catch the first c04 child. However
> test="../../c04[1]" does not seem to be doing the trick.
> Any suggestions? I'm using XSLT 2.0.
> Thanks,
> Nathan

Current Thread