• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

XSL Transformation - Selecting single element from multiple instances of an element

 
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello All,

I have a requirement for selecting a single element for processing

Input File has multiple instances of <Contact> element
...
<Contact>ABC</Contact>
<Contact>XYZ</Contact>
<Contact>PQR</Contact>
...

I want to process only the first element to get the output
<Customer>ABC</Customer>

The following XSL will process all the elements.
<xsl:for-each select="Contact">
<Customer>
<xsl:value-of select="."/>
</Customer>
</xsl:for-each>

What should be the XSL syntax to get the desired output.

Thanks in advance,
- Pradeep
 
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try using the position() function.

<xsl:for-each select="Contact[position() = 1]">
<Customer>
<xsl:value-of select="."/>
</Customer>
</xsl:for-each>

Something of that sort. I haven't tested this so you might
have to lookup the function.

- m
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic