• Post Reply Bookmark Topic Watch Topic
  • New Topic

xsl:apply-templates problem  RSS feed

 
Bipul Kumar Singh
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have a xslt
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl utput omit-xml-declaration="yes" method="xml" indent="yes" encoding="iso8859-1"/>
<xsl:key name="speaker" match="SPEECH" use="SPEAKER"/>
<xsl:template match="/">
<!-- Do this to suppress the display of all the text in the document-->
<SCENE>
<xsl:apply-templates select="SCENE/SPEECH[count(. | key('speaker', SPEAKER)[1]) = 1]/SPEAKER"/>
<!--<xsl:apply-templates select="//SPEAKER"/>-->
</SCENE>
</xsl:template>
<xsl:template match="SPEAKER">
<xsl:variable name="temp" select="."/>
<LINES>
<!-- Collect all of the lines spoken by the current speaker -->
<SPEAKER>
<xsl:value-of select="$temp"/>
</SPEAKER>
<xsl:for-each select="//SPEECH[SPEAKER=$temp]/LINE">
<LINE>
<xsl:value-of select="."/>
</LINE>
</xsl:for-each>
</LINES>
</xsl:template>
</xsl:stylesheet>

which i want to apply to this xml
<?xml version="1.0" encoding="UTF-8"?>
<SCENE>
<SPEECH>
<SPEAKER>BERNARDO</SPEAKER>
<LINE>Who's there?</LINE>
</SPEECH>
<SPEECH>
<SPEAKER>FRANCISCO</SPEAKER>
<LINE>Nay, answer me: stand, and unfold yourself.</LINE>
</SPEECH>
<SPEECH>
<SPEAKER>BERNARDO</SPEAKER>
<LINE>Long live the king!</LINE>
</SPEECH>
<SPEECH>
<SPEAKER>FRANCISCO</SPEAKER>
<LINE>Bernardo?</LINE>
</SPEECH>
</SCENE>
-----------------------------------------------------------------

Can anyone pl. tell me how is this XSLT working? I mean how the xsl:apply-templates is working here in conjunction with key() and count() !!!

I'm stumped and not able to figure it out

Thanks in advance

Regds,
Bipul
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!