Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > XSL newbie question: how do I only show the first or second item?

Reply
Thread Tools

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

 
 
Robby
Guest
Posts: n/a
 
      10-11-2005
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
 
Reply With Quote
 
 
 
 
Martin Honnen
Guest
Posts: n/a
 
      10-11-2005


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/
 
Reply With Quote
 
 
 
 
Robby
Guest
Posts: n/a
 
      10-11-2005
In article <434ba216$0$26227$(E-Mail Removed)-online.net>,
http://www.velocityreviews.com/forums/(E-Mail Removed) 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
 
Reply With Quote
 
Harrie
Guest
Posts: n/a
 
      10-11-2005
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
 
Reply With Quote
 
Robby
Guest
Posts: n/a
 
      10-11-2005
> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: When running Ant on command line, how to not-show its WARNING messages and only show ERROR message? Roedy Green Java 5 12-13-2011 05:49 PM
Re: When running Ant on command line, how to not-show its WARNING messages and only show ERROR message? John B. Matthews Java 0 12-09-2011 05:19 PM
xsl to group elements? [xsl newbie] Rob Smegma XML 1 09-26-2005 10:59 AM
XSL Question tp xsl:for-each and xsl:variable schaf@2wire.ch XML 1 05-27-2005 09:25 PM
Datalist selects Item after first click, but does apply the SelectedItemTemplate after the second click only Dirk Meusel ASP .Net 1 08-19-2003 09:56 AM



Advertisments