• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

xsl:apply-templates problem

 
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
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!