Jump to content
Sign in to follow this  
jo_rocks

xslt and xpath problem

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

Share this post


Link to post
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> 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...