|
Subject: Re: [xsl] foreach, preceding-sibling::node() and following-sibling::node() From: "Mingqiang Yu" <myu@xxxxxxxx> Date: Wed, 26 Oct 2005 20:50:30 -0600 (MDT) |
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',
"1905A01449")">1905A01449</a><i>in vacuo</i> and theory of the
ferromagnetic state [see Abs. <a href="javascript:frLink('FRLink','all',
"1905A01449")">1914A00343</a>, <a
href="javascript:frLink('FRLink','all',
"1905A01449")">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',
"{$idlinkVal}");">
<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 |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| Re: [xsl] foreach, preceding-siblin, Ragulf Pickaxe | Thread | Re: [xsl] foreach, preceding-siblin, David Carlisle |
| [xsl] Embedded Stylesheets + doc() , David Riggs | Date | [xsl] namespace aware template matc, tom . kirkpatrick |
| Month |