It's not a secret anymore!*
The moose likes XML and Related Technologies and the fly likes xsl:apply-templates problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "xsl:apply-templates problem" Watch "xsl:apply-templates problem" New topic
Author

xsl:apply-templates problem

Bipul Kumar Singh
Greenhorn

Joined: Jul 08, 2004
Posts: 6
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
 
jQuery in Action, 2nd edition
 
subject: xsl:apply-templates problem
 
Similar Threads
XPath/XSLT: Reverse axis really isn't?
XSLT Transformation error
why is the output not displayed
WSAD 5 XML/XSL Validator
xml namespace and xsl transformation problem