xsl-list
[Top] [All Lists]

Re: [xsl] conditional display of content

2008-05-30 21:29:52
Thank you Andrew,

I have copied the below code into my stylesheet. and it is not
working. Can you help in getting the output. Anything i have to modify
from this.


<xsl:key name="role-by-id" match="pbl:role" use="@xml:id"/>

<xsl:template match="pbl:roleref>
 <xsl:value-of select="key('role-by-id', substring-after(@href, '#'))"/>
</xsl:template>

Regards,
Ganesh


On Tue, May 27, 2008 at 2:42 PM, Andrew Welch 
<andrew(_dot_)j(_dot_)welch(_at_)gmail(_dot_)com> wrote:
2008/5/27 Ganesh Babu N <nbabuganesh(_at_)gmail(_dot_)com>:
This is the XML file:

horrible sample XML fragment by the way... what's wrong with indenting it?

My requirement is to display the corresponding the role/personname in
the speaker tag. The condition is id and href should match.

<xsl:template match="pbl:roleref>
     <xsl:if test="substring-after(@href),#) =
//pbl:castmember/pbl:role/@xml:id">
           <xsl:value-of select="//pbl:castmember/pbl:role/personname"/>
     </xsl:if>
</xsl:template>

Your xpath needs to at least be //pbl:castmember/pbl:role[$id =
@xml:id]/personname

where $id is a variable defined before the select as:

substring-after(@href), '#')    (notice the single quotes around the
hash... or "pound" sign if you speak American)

or just use substring-after(current()/@href), '#') directly in the XPath.

Ultimately though this should be rewritten to use a key:

<xsl:key name="role-by-id" match="pbl:role" use="@xml:id"/>

and then just

<xsl:template match="pbl:roleref>
 <xsl:value-of select="key('role-by-id', substring-after(@href, '#'))"/>

If the lookup value doesn't exist in the key then nothing is returned.

--
Andrew Welch
http://andrewjwelch.com
Kernow: http://kernowforsaxon.sf.net/

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>