[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: foreach, preceding-sibling::node() and following-

Subject: Re: foreach, preceding-sibling::node() and following-sibling::node()
From: "Mingqiang Yu" <myu@xxxxxxxx>
Date: Wed, 26 Oct 2005 20:50:30 -0600 (MDT)
javascript sibling
Sorry that I didn't make myself very clear. I make the xml too simple.
I've thought it will be easier. But guess I'm wrong. Now I'm adding some
more details.

This is the xml file structure I'm using:
<rec>
  <zabs>
     <abs db="db1"> Experiment regarding the theory of Langevin [see Abs.
         <idlink>1905A01449</idlink>].  <i>in vacuo</i> and theory of the
         ferromagnetic state [see Abs. <idlink>1914A00343</idlink>,
         <idlink>1914A00344</idlink>].
     </abs>
  </zabs>
  <ztit>
     <tit> Title name </title>
  </ztit>
</rec>

Of course, I simplify the xml file. But the structure is like this. For
the output regarding the <abs> tag, I need the output like this:

Experiment regarding the theory of Langevin [see Abs.<a
href="javascript:frLink('FRLink','all',
&quot;1905A01449&quot;)">1905A01449</a><i>in vacuo</i> and theory of the
ferromagnetic state [see Abs. <a href="javascript:frLink('FRLink','all',
&quot;1905A01449&quot;)">1914A00343</a>, <a
href="javascript:frLink('FRLink','all',
&quot;1905A01449&quot;)">1914A00344</a>.

I've been using this piece of stylesheet to handle. The purpose is that,
when it's <idlink> tag, I want to output a href hyperlink for the value;
otherwise, just output whatever in there. The $field variable is passed to
this template which is either tit or abs in this case. (the <tit> and
<abs> tag):

<xsl:when test="$field='tit' or $field='abs'">
  <xsl:choose>
    <xsl:when test="idlink">
      <xsl:copy-of select="idlink[1]/preceding-sibling::node()"/>
      <xsl:for-each select="idlink">
        <xsl:variable name="idlinkVal">
          <xsl:value-of select="."/>
        </xsl:variable>
        <a href="javascript:frLink('FRLink','all',
&quot;{$idlinkVal}&quot;);">
        <xsl:value-of select="$idlinkVal"/>
        </a>
        <xsl:copy-of
select="following-sibling::node()[generate-id(current())=generate-id(preceding-sibling::idlink[1])]"/>
       </xsl:for-each>
     </xsl:when>
     <xsl:otherwise>
       <xsl:copy-of select="@*|node()"/>
     </xsl:otherwise>
   </xsl:choose>
</xsl:when>

But the problem is, the
following-sibling::node()[generate-id(current())=generate-id(preceding-sibling::idlink[1])always
gives me the text including the next idlink tag while what I need is just
the text right before next <idlink>.

Sorry again if this still confuses you. Maybe I'm just stuck on some basic
concept and cannot get around it. Thanks a lot for your help.

Ming

> I am not sure what you want either.
>
> For the examples of your input and output the following three
> templates should work:
>
> <xsl:template match="abs">
>   <xsl:apply-templates/>
> </xsl:template>
>
> <xsl:template match="idlink">
>   <xsl:variable name="urlnumber" select="count(preceding::idlink)+1"/>
>   <a href="url{$urlnumber}"><xsl:value-of select="."/></a>
> </xsl:template>
>
> <xsl:template match="i|b|u|em"> <!-- And more elements -->
>   <xsl:copy>
>     <xsl:apply-templates/>
>   </xsl:copy>
>
> <!-- This template is not needed as this is the same as the default
> template for text nodes, but is added for clarity: -->
> <xsl:template match="text()">
>   <xsl:value-of select="."/>
> </xsl:template>
>
> Is this what you need?
>
> Regards,
> Ragulf Pickaxe :-)
>
> On 10/26/05, David Carlisle <davidc@xxxxxxxxx> wrote:
>>
>>
>> > Actually, I do want the content between the two idlinks and, that's
>> where
>> > I'm stuck. This is what I need:
>> > Xml input file:

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.