XSL newbie question: how do I only show the first or second item?

Discussion in 'XML' started by Robby, Oct 11, 2005.

  1. Robby

    Robby Guest

    Hello,

    How can I show only the first AddressLine (or just the second one) in
    FormattedAddress?

    I have been trying to do this, but can't get it to work...

    What I have now is:

    <xsl:template match="FormattedAddress">
    <xsl:value-of select="[AddressLine()=1]"/>
    </xsl:template>

    Any help would be very much appreciated.

    Cheers,
    Roberto
     
    Robby, Oct 11, 2005
    #1
    1. Advertising

  2. Robby wrote:


    > How can I show only the first AddressLine (or just the second one) in
    > FormattedAddress?


    The XPath expression
    AddressLine
    gives you a node set, to filter that you can add a predicate in square
    brackets, if you are looking for an element in that node set with a
    particular index then use
    AddressLine[index]
    The first element in a nodeset has index 1!

    That is really basic stuff, take a look at some XPath tutorial, for instance
    <http://www.zvon.org/xxl/XPathTutorial/General/examples.html>

    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, Oct 11, 2005
    #2
    1. Advertising

  3. Robby

    Robby Guest

    In article <434ba216$0$26227$-online.net>,
    says...
    >
    >
    > Robby wrote:
    >
    >
    > > How can I show only the first AddressLine (or just the second one) in
    > > FormattedAddress?

    >
    > The XPath expression
    > AddressLine
    > gives you a node set, to filter that you can add a predicate in square
    > brackets, if you are looking for an element in that node set with a
    > particular index then use
    > AddressLine[index]
    > The first element in a nodeset has index 1!
    >
    > That is really basic stuff, take a look at some XPath tutorial, for instance
    > <http://www.zvon.org/xxl/XPathTutorial/General/examples.html>
    >
    > --
    >
    > Martin Honnen
    > http://JavaScript.FAQTs.com/
    >


    Martin,

    Thank you for your advice.
    I looked up the tutorial, which seems to be very clear, with good
    exemples.

    I tried to translate it to my situation, and came to this:

    <xsl:template match=
    "ApplicantDetails/Applicant/ApplicantAddressBook/FormattedNameAddress/Ad
    dress/FormattedAddress">
    <xsl:value-of select="/AddressLine[1]"/>
    </xsl:template>

    But unfortunately, this doesn't work...
    Tried to play with and without slashes, but no luck.

    What went wrong?

    Any help would be very much appreciated.

    Kind regards,
    Robby
     
    Robby, Oct 11, 2005
    #3
  4. Robby

    Harrie Guest

    Robby said the following on 10/11/2005 14:34 +0200:

    > I tried to translate it to my situation, and came to this:
    >
    > <xsl:template match=
    > "ApplicantDetails/Applicant/ApplicantAddressBook/FormattedNameAddress/Ad
    > dress/FormattedAddress">
    > <xsl:value-of select="/AddressLine[1]"/>
    > </xsl:template>


    <xsl:template match="AddressLine[1]">
    <xsl:value-of select="." />
    </xsl:template>

    There's probably a better way (I'm no expert).

    --
    Regards
    Harrie
     
    Harrie, Oct 11, 2005
    #4
  5. Robby

    Robby Guest

    > I tried to translate it to my situation, and came to this:
    >
    > <xsl:template match=
    > "ApplicantDetails/Applicant/ApplicantAddressBook/FormattedNameAddress/Ad
    > dress/FormattedAddress">
    > <xsl:value-of select="/AddressLine[1]"/>
    > </xsl:template>
    >
    > But unfortunately, this doesn't work...


    Dear people,

    Got it. I was trying to do it too complicated.
    And learned that you can't have an xsl:template match inside another...
    ;-)

    What did the trick, was simply:
    <xsl:value-of select=
    "ApplicantDetails/Applicant/ApplicantAddressBook/FormattedNameAddress/Ad
    dress/FormattedAddress/AddressLine[1]" />

    Thanks to all for your kind help,
    Robby
     
    Robby, Oct 11, 2005
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Dirk Meusel
    Replies:
    1
    Views:
    3,050
    Dirk Meusel
    Aug 19, 2003
  2. Sparky Arbuckle

    Only First Shopping Cart Item Displays

    Sparky Arbuckle, Feb 20, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    309
    Sparky Arbuckle
    Feb 20, 2005
  3. Drulli Rokk
    Replies:
    3
    Views:
    768
    David Andriana
    Oct 1, 2003
  4. Replies:
    1
    Views:
    3,649
    A. Bolmarcich
    May 27, 2005
  5. John B. Matthews
    Replies:
    0
    Views:
    776
    John B. Matthews
    Dec 9, 2011
Loading...

Share This Page