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 September 16th, 2014, 03:45 PM
Friend of Wrox
 
Join Date: Apr 2013
Posts: 101
Thanks: 14
Thanked 0 Times in 0 Posts
Default How to display 2 nodes information

Could someone help me modify my xslt code below so I can get output for both QualifyingRelationshipCode and QualifyingRelationshipText

Right now I am only getting output for QualifyingRelationshipCode but I am not getting QualifyingRelationshipText output.
Here is the output I am getting which is wrong. this:

Code:
<ext:QualifyingRelationship>
<ext:QualifyingRelationshipCode>CHLDTOGTHR</ext:QualifyingRelationshipCode>
<ext:QualifyingRelationshipCode>LIVTOGTHR</ext:QualifyingRelationshipCode>
<ext:QualifyingRelationshipText/>
<ext:QualifyingRelationshipText/>
</ext:QualifyingRelationship>
Result I want to see

Code:
<ext:QualifyingRelationship>
<ext:QualifyingRelationshipCode>CHLDTOGTHR</ext:QualifyingRelationshipCode>
<ext:QualifyingRelationshipCode>LIVTOGTHR</ext:QualifyingRelationshipCode>
<ext:QualifyingRelationshipText>Have a child together</ext:QualifyingRelationshipText>
<ext:QualifyingRelationshipText>Lived Together</ext:QualifyingRelationshipText>
</ext:QualifyingRelationship>
My xslt code

Code:
<xsl:for-each select="MNProtectionOrderAdditional/QualifyingRelationships">
	<ext:QualifyingRelationship>
	<xsl:for-each select="QualifyingRelationship"> 
		<ext:QualifyingRelationshipCode>
		<xsl:value-of select="@Word"/>
	</ext:QualifyingRelationshipCode>
		</xsl:for-each>
		<xsl:for-each select="QualifyingRelationship">
	<ext:QualifyingRelationshipText>
	 	<xsl:value-of select="QualifyingRelationship"/>
	</ext:QualifyingRelationshipText>
		</xsl:for-each>
	</ext:QualifyingRelationship>
	</xsl:for-each>
Here is the xml document which is transformed by the code above (xslt)

XML Code

Code:
<QualifyingRelationships>
    <QualifyingRelationship Word="CHLDTOGTHR">Have a child together</QualifyingRelationship>
    <QualifyingRelationship Word="LIVTOGTHR">Lived Together</QualifyingRelationship>
</QualifyingRelationships>
 
Old September 16th, 2014, 03:52 PM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

Inside of the for-each the context node is the element node and you can output its string value with value-of select=".".
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
The Following User Says Thank You to Martin Honnen For This Useful Post:
winkimjr2 (November 25th, 2014)
 
Old September 16th, 2014, 05:22 PM
Friend of Wrox
 
Join Date: Apr 2013
Posts: 101
Thanks: 14
Thanked 0 Times in 0 Posts
Default

I did change my xslt code as you recommended but the output I am getting is not exactly what I want.
I have 2 codes for QualifyingRelationshipCode each of which has its own QualifyingRelationshipText.

I want <ext:QualifyingRelationshipCode> to be followed by its <ext:QualifyingRelationshipText>
I added this to my xslt:

Modified code:

Code:
<xsl:for-each select="MNProtectionOrderAdditional/QualifyingRelationships">
<ext:QualifyingRelationship>
<xsl:for-each select="QualifyingRelationship">
<ext:QualifyingRelationshipText>
<xsl:value-of select="."/>
</ext:QualifyingRelationshipText>
</xsl:for-each>
</ext:QualifyingRelationship>
Output produced by modified code

Code:
<ext:QualifyingRelationship>
<ext:QualifyingRelationshipCode>CHLDTOGTHR</ext:QualifyingRelationshipCode>
<ext:QualifyingRelationshipCode>LIVTOGTHR</ext:QualifyingRelationshipCode>
<ext:QualifyingRelationshipText>Have a child together</ext:QualifyingRelationshipText>
<ext:QualifyingRelationshipText>Lived Together</ext:QualifyingRelationshipText>
</ext:QualifyingRelationship>

The out put I want should be
Code:
<ext:QualifyingRelationshipCode>CHLDTOGTHR</ext:QualifyingRelationshipCode>
<ext:QualifyingRelationshipTest>Have a child together</ext:QualifyingRelationshipText>
<ext:QualifyingRelationshipCode>LIVTOGTHR</ext:QualifyingRelationshipCode>
<ext:QualifyingRelationshipTest>Lived Together</ext:QualifyingRelationshipText>
 
Old September 17th, 2014, 06:29 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

Well in your first post you asked for a different output. If you want to have Code and Test together then use e.g.
Code:
    <xsl:for-each select="QualifyingRelationship"> 
        <ext:QualifyingRelationshipCode>
          <xsl:value-of select="@Word"/>
            </ext:QualifyingRelationshipCode>
                <ext:QualifyingRelationshipText>
           <xsl:value-of select="."/>
            </ext:QualifyingRelationshipText>
    </xsl:for-each>
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
The Following User Says Thank You to Martin Honnen For This Useful Post:
winkimjr2 (September 17th, 2014)





Similar Threads
Thread Thread Starter Forum Replies Last Post
Display all nodes of an XML eruditionist XSLT 1 October 4th, 2010 11:54 AM
Selective Display of information on a panel JohnInPomeroy BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 5 March 21st, 2010 05:07 AM
Display only unique Nodes kylektran XSLT 1 July 17th, 2009 08:41 AM
HOW TO: Display specified # of nodes kwilliams XSLT 2 October 5th, 2005 11:04 AM
Display nodes from xml nambati XSLT 2 September 17th, 2004 07:57 AM





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