Search

hi,

Can any one please tell how to select a data of a particular position using xslt..

thanks

You're going to have to be a little more forthcoming than that. Can we have a reference to what you mean? Otherwise it would just be guesswork.

Do you mean a position of a node within a nodeset?

Can we have some XML and XSLT and what you're trying to achieve.

Cheers.

i have 3 datas in my particular datasource..

my out put is by this i got

uthaya rajneesh thamizh

but i want only the 2nd data (rajneesh) only..

plz tell how i get a particular data only using xslt

You need to use position(), but I can't show you how unless you give me a context.

Like I said before.

this is my template

  <xsl:template name="home-banner">

    <xsl:for-each select="data/page-banners/entry"> 

    <xsl:value-of  select="title" />

</xsl:for-each>

 </xsl:template>

i need 2nd position title only..

thanks

Ok, your best bet is to use apply-templates rather than for-each as you can directly select a node, rather than iterate over each one until you match the second one.

<xsl:template name="home-banner">

    <xsl:apply-templates select="data/page-banners/entry[position() = 2]" mode="get-title" />

</xsl:template>

<xsl:tamplate match="page-banners/entry" mode="get-title">

    <xsl:value-of select="title/text()" />

</xsl:tamplate>

We use a 2 as node indexes in xPath always start at 1, not 0 as in other languages.

I've added the mode attribute in there, as the matched template is being called from a named template, and we can avoid conflicts with any other templates you may use on page-banners/entry.

Hope this is what you're after?

how i use apply-templates rather than for-each in master.xsl. it couldn't working correctly in master.xsl.

@uthayavin This article might help you understand the different uses of apply-templates versus for-each.

As for your specific issue, if you are to stick with for-each, you can modify your code as below to achieve what you're looking for.

<xsl:template name="home-banner">
    <xsl:for-each select="data/page-banners/entry[2]">
        <xsl:value-of select="title" />
    </xsl:for-each>
</xsl:template>

Notice that there is a square bracket after entry.

I want to add you have been asking a lot of questions on the forum. We're all quite happy to help out, your questions are all quite basic and does not demonstrate that you have done the necessary effort in research on your part before asking the community for help.

To ensure a positive and productive response from the generous members that have kindly donated their time to helping you, please make sure you do the following:

  1. Structure your thread cleanly and politely
  2. Describe the steps you have taken and the research you have done prior to asking the question
  3. Provide all the necessary reference code (ideally via Pastie or Gist).
  4. If your question is related to XSLT, provide both XML and XSLT. If your question is related to the system or its extensions, provide your Symphony version number, the corresponding error message and the script in question.

thanks i will try

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details