Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 8th, 2011, 05:42 PM
Authorized User
 
Join Date: Jul 2010
Posts: 74
Thanks: 23
Thanked 0 Times in 0 Posts
Question How to just get one node attribute value from duplicate node

The input XML:
Code:
<request attr1="John" attr2="King">
  <telephoneNumber telephone="1234567890">
    <detail value="P" tag="Other" />
    <detail value="789" tag="TT" />
    <detail value="N" tag="Sw" />
    <detail value="B" tag="HT" />
  </telephoneNumber>
  <telephoneNumber telephone="9876543210">
    <detail value="o" tag="Other" />
    <detail value="789" tag="TT" />
    <detail value="G" tag="Sw" />
    <detail value="K" tag="HT" />
  </telephoneNumber>
</request>
I want the output :
Code:
<request>
  <parameter>
    <Attr1>John</Attr1>
    <Attr2>King</Attr2>
    <TT>789</TT>
    <Tel>1234567890</Tel>
    <Tel>9876543210</Tel>
  </parameter>
</request>
The detail/@TT always has the same value in the input, but for the output I only need one, means I do not want the value 789789 for the output TT node, I want 789 for the output TT node.

Any idea how to use XSL 1.0 to do that?

Thank you in advance.

Last edited by JohnKiller; December 8th, 2011 at 05:56 PM..
 
Old December 9th, 2011, 04:39 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

No idea where you are starting from, but something like this:

telephoneNumber[1]/detail[@tag='TT]/@value

This assumes that both TT values are the same and you just want to first one.

To be honest I'm not even sure how you are are generating the original incorrect value as you haven't shown us your code, so this might be completely wrong for you.
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
 
Old December 9th, 2011, 10:40 AM
Authorized User
 
Join Date: Jul 2010
Posts: 74
Thanks: 23
Thanked 0 Times in 0 Posts
Default

The input is generated by Java. After that I want to do the format translation. And I just copied them from my XML file (the phone number is not right, but in my code I just did the test using these two numbers). And the output was right except the TT field, it is 789789, I only want one TT value-789, ont append them together. Hope I tell my problem clearly.

In the input, I did not copy <?xml version="1.0" encoding="UTF-8"?> in the first line.

Sorry for any misunderstanding. And thank you for your reply.
 
Old December 9th, 2011, 10:49 AM
Authorized User
 
Join Date: Jul 2010
Posts: 74
Thanks: 23
Thanked 0 Times in 0 Posts
Default

Your solution works, and yes, I only need the first TT.

Thanks.

Quote:
Originally Posted by samjudson View Post
No idea where you are starting from, but something like this:

telephoneNumber[1]/detail[@tag='TT]/@value

This assumes that both TT values are the same and you just want to first one.

To be honest I'm not even sure how you are are generating the original incorrect value as you haven't shown us your code, so this might be completely wrong for you.





Similar Threads
Thread Thread Starter Forum Replies Last Post
How to pass node attribute? gopalbaliga XSLT 1 May 16th, 2011 06:43 AM
Displaying data as a Parent Node with Left Node and Right Node Manoj Bisht Visual Basic 2008 Professionals 0 April 2nd, 2009 02:34 AM
Get a node value using attribute name IronStar XSLT 4 May 29th, 2008 04:28 PM
Duplicate nodes get the value from first node dev.user06 XSLT 6 August 8th, 2006 11:33 AM
Avoid duplicate node values nambati XSLT 1 September 8th, 2004 02:41 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.