Jump to content

xslt and xpath problem


jo_rocks
 Share

Recommended Posts

Hi all,I have this XSLT:

<?xml version="1.0" encoding="ISO-8859-1"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:output method="xml" version="1.0" encoding="iso-8859-1" indent="yes"/><xsl:template match="/"><xsl:apply-templates select="//prime"/></xsl:template> <xsl:template match="prime">  <xsl:apply-templates select="note[@style='tt']" />   </xsl:template> <xsl:template match="note/rss/channel"> <xsl:apply-templates select="item"></xsl:template><xsl:template match="item"><item> <title>  <xsl:value-of  select="title"/> </title> <description>  <xsl:value-of  select="description"/> </description> <pubDate>  <xsl:value-of  select="pubDate"/> </pubDate></item></xsl:template><xsl:template match="prime">  <xsl:apply-templates select="note[@style='sms']" />   </xsl:template> <xsl:template match="note/rss/channel"> <xsl:apply-templates select="item"></xsl:template><xsl:template match="item"><item> <title>  <xsl:value-of  select="title"/> </title>  <pubDate>  <xsl:value-of  select="pubDate"/> </pubDate></item></xsl:template></xsl:stylesheet>

I want to show note type =tt and note type = sms in the same page because the content of each type is different, the problem with this xslt is that the note type sms is overwritting the note type = tt, in other words, it's only showing the note type= sms. How can I solve this... Thanks all

Link to comment
Share on other sites

You could do it this way:

<?xml version="1.0" encoding="ISO-8859-1"?><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:output method="xml" version="1.0" encoding="iso-8859-1" indent="yes"/> <xsl:template match="/">  <xsl:apply-templates select="//prime"/></xsl:template> <xsl:template match="prime">  <xsl:apply-templates select="note"/></xsl:template> <xsl:template match="note">  <xsl:choose>    <xsl:when test="@style='tt'">	    <xsl:apply-templates mode="tt"/>    </xsl:when>    <xsl:when test="@style='sms'">	    <xsl:apply-templates mode="sms"/>    </xsl:when>  </xsl:choose></xsl:template><xsl:template match="note/rss/channel" mode="tt">  <xsl:apply-templates select="item" mode="tt"></xsl:template><xsl:template match="note/rss/channel" mode="sms">  <xsl:apply-templates select="item" mode="sms"></xsl:template><xsl:template match="item" mode="tt"><item>  <title>	  <xsl:value-of  select="title"/>   </title>   <description>	 <xsl:value-of  select="description"/>   </description>    <pubDate>	  <xsl:value-of  select="pubDate"/>   </pubDate></item></xsl:template><xsl:template match="item" mode="sms"><item>  <title>	  <xsl:value-of  select="title"/>   </title>    <pubDate>	  <xsl:value-of  select="pubDate"/>   </pubDate></item></xsl:template> </xsl:stylesheet> 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...