Answered XSLT nodes with Xpath

  • viernes, 20 de abril de 2012 22:31
     
      Tiene código

    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

Todas las respuestas

  • sábado, 21 de abril de 2012 9:22
     
     Respondida

    Having two different templates with the same priority for the same elements does not make sense, unless you use modes to distinguish different processing steps.

    However if you want to make sure that certain elements are processed then you can of course process the union of two expressions as in

      <xsl:apply-templates select="note[@style = 'tt'] | note[@style = 'sms']"/>

    Or you might simply do

      <xsl:apply-templates select="note[@style='tt' or @style = 'sms']" />

    Or nothing prevents you from putting two or more apply-templates into one template so

      <xsl:apply-templates select="note[@style='tt']" />

      <xsl:apply-templates select="note[@style='sms']" />

    in the same template is also possible.


    MVP Data Platform Development My blog

    • Marcado como respuesta t_manpt sábado, 21 de abril de 2012 15:06
    •  
  • sábado, 21 de abril de 2012 15:06
     
     

    Hi Martin,

    Thanks again for your help, it worked!

    Thanks