tags:

views:

75

answers:

1

HI,

I want to select all nodes other than first node.My xsl and xml are like this but I am not getting the output for it.

<Categories>
  <Category>
    <Title>Business</Title>
  </Category>
  <Category>
    <Title>Politics</Title>
  </Category>
</Categories>

my xsl

<xsl:template match="Categories">
    <xsl:variable name="restallTitles">
      <xsl:value-of select="//*[position() &gt; 1]"/>
    </xsl:variable>
    <xsl:for-each select="Categories/Category">
      <xsl:if test="$restallTitles">
        <xsl:choose>
          <xsl:when test="position() mod 2 = 1">
            <li class=""><xsl:value-of select="Title"/></li>
          </xsl:when>
          <xsl:otherwise>
            <li class="odd"><xsl:value-of select="Title"/></li>
          </xsl:otherwise>
        </xsl:choose>               
      </xsl:if>
    </xsl:for-each>
</xsl:template>

Its not showing any output ...anyone is having idea where i m getting wrong::

Edited:: I m expecting output "politics" in this case but basically i want all but the "Business"

+1  A: 

If you mean "all <Category>s except the first in the document", then try:

<xsl:for-each select="(Categories/Category)[position() gt; 1]">
  <li>
    <xsl:if test="position() mod 2 = 1">
      <xsl:attribute name="class">odd</xsl:attribute>
    </xsl:if>
    <a class="video video-lightbox ratio-16-9" href="{$url1}">
      <xsl:value-of select="Title"/>
    </a>
  </li>
</xsl:for-each>
Tomalak
i tried your way but still its not showing the output
TSSS22
Your problem is that you use an `<xsl:template match="Categories">`, and within it an `<xsl:for-each select="Categories/Category">`. XPath is relative, it must be `<xsl:for-each select="Category">` since you *are* in `Categories` context already when it runs.
Tomalak
Thanks I got it ...or I should use <xsl:template match="/"> and <xsl:for-each select="Categories/Category>..........Its working fine now..........Thanks once again....
TSSS22
I think that `<xsl:template match="Categories">` is nicer in this case.
Tomalak