Re: Select on Text Node, XML Out of Ancestors

Subject: Re: Select on Text Node, XML Out of Ancestors
From: James Clark <jjc@xxxxxxxxxx>
Date: Mon, 01 Nov 1999 22:22:25 +0700
Try:

<xsl:template match="/">
  <xsl:copy-of select="//record[.//subfield='0039-310X']"/>
</xsl:template>


John Robert Gardner wrote:
> 
> I've looked over the replies to Clark Evans' question of 10/19 selecting
> the SiO2 text (subject line XSL: Returning a selected node in the context
> of it's ancestors), and I'm looking to do omething similar, but not quite
> so detailed viz. attributes, so I'm having trouble adapting the solution.
> 
> For my XML:
> <root>
> ....lots like teh following...
> 
> <record>
>         .... lots of these daa-field elements ....
> 
>         <data-field type="773" indicator="0">
>                 <subfield code="a">Soemthing Here</subfield>
>                 <subfield code="g">Number 2, 14, (something) blah
>                         </subfield>
>                 <subfield code="x">0039-310X</subfield>
>         </data-field>
> <record>
> ......lots more ......
> </root>
> 
> I'm looking to select (ultimately extract) all the records with subfield
> 0039-310X, I've diligently read through all of the W3C spec in detail, and
> I can piece together bits from reading everyone's suggestions, but some of
> it just baffles me, and all I want it to do is go find 0039-310X and then
> simply walk back up (per Ken Holman, but I got lost in his code
> eventually) to the ancestor <record>, grab all contents, and append to the
> output file.  There are no id attributes, but there are other attributes
> and elements within each selected record, all of which, of course, I want
> to put into the output unchnaged.
> 
> I liked david Carlisle's solution (b/c it was short and I could almost
> grasp it), and I've adopted it as follows:
> 
> <?xml version="1.0"?>
> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
>                  version="1.0">
> <xsl:output method="xml"/>
> <xsl:variable name="x"
>               select="generate-id(//subfield[.='0039-310X'])"/>
> <xsl:template match="*">
> <xsl:if test="descendant-or-self::*[generate-id(.)=$x]">
> <xsl:copy>
> <xsl:copy-of select="@*"/>
> <xsl:apply-templates/>
> </xsl:copy>
> </xsl:if>
> </xsl:template>
> </xsl:stylesheet>
> 
> Unfortunately, I only got back a fragment of the record after running it
> through xt:
> 
> <root>
>         <record type="naa">
>                 <data-field tag="773" ind1="0">
>                         <subfield code="x">0039-310X</subfield>
>                 </data-field>
>         </record>
> </root>
> 
> Did I miss something with David's note:
> 
> bash-2.01$ xt ansc.xml ansc2.xsl
> <vendor name="james">
>  <product id="1234">
>   <material>SiO2</material>
>  </product>
> 
> </vendor>
> 
> I'm not sure I know what "bash" is.
> 
> I'm very sure that in spite of my careful reading I'm missing something
> obvious which will ensure complete transmission of _ALL_ the record in
> which subfield 0039-310X is found, not just the fragment above.
> 
> Thanks for any help in advance, folks-
> 
> jr
> 
> =-=-=-=-=-=-=-=-=-==-=-=-=
> John Robert Gardner
> XML Engineer
> ATLA-CERTR
> ------------------------------------------------------------
> http://vedavid.org/
> http://www.purl.org/CERTR/
> 
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread