[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

looping

Subject: looping
From: "Ahsan" <ahsan_hussain@xxxxxxxxxxxxx>
Date: Sun, 22 Jun 2003 17:24:42 -0700
xsl loop child nodes
Attached below is the XML and the XSL files. I would like to print the
attribute values of all tags inside the inner <HSDataContainerType> tag for
inputs as well as outputs such as licenceKey, fromCurrency etc. With my XSL
it only prints the first attribute value. How can print them all?

I want to use a loop to achieve this since i would not know the number of
inputs/outputs everytime.

Thanks in advance-

Ahsan

XML:

<HSContract contractName="ConvertToNum">
	<HSDataContainerType name="Inputs">
		<HSDataContainerType name="ConvertToNum">
			<HSString name="licenseKey" xmlNodeType="1" />
			<HSString name="fromCurrency" xmlNodeType="1" />
			<HSString name="toCurrency" xmlNodeType="1" />
			<HSDouble name="amount" required="true" xmlNodeType="1" />
			<HSBoolean name="rounding" required="true" xmlNodeType="1" />
		</HSDataContainerType>
	</HSDataContainerType>
	<HSDataContainerType name="Outputs">
		<HSDataContainerType name="ConvertToNumResponse">
			<HSDouble name="ConvertToNumResult"/>
			<HSBoolean name="roundingResult" required="true" xmlNodeType="1" />
		</HSDataContainerType>
	</HSDataContainerType>
</HSContract>

XSL:

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="HSDataContainerType/HSDataContainerType">
	<!-- if(parent's attribute is Input, print it) -->
	<xsl:if test="contains(../@name, 'Inputs')">
		<b><p><xsl:value-of select="../@name"/>:</p></b>

		<xsl:comment>loop thru all elements in 'Inputs'</xsl:comment>

		<xsl:for-each select=".">
			<!-- if the child node is an HSString, print its name -->
			<xsl:if test="contains(name(child::*), 'HSString')">
				<xsl:comment>print child's attrib!</xsl:comment>
				<xsl:value-of select="./HSString/@name"/>
			</xsl:if>
			<!-- if the child node is an HSString, print its name -->
			<xsl:if test="contains(name(child::*), 'HSDouble')">
				<xsl:comment>print child's attrib!</xsl:comment>
				<xsl:text>HERE!</xsl:text>
				<xsl:value-of select="./HSDouble/@name"/>
			</xsl:if>
			<!-- if the child node is an HSString, print its name -->
			<xsl:if test="contains(name(child::*), 'HSBoolean')">
				<xsl:comment>print child's attrib!</xsl:comment>
				<xsl:text>HERE!</xsl:text>
				<xsl:value-of select="./HSBoolean/@name"/>
			</xsl:if>
		</xsl:for-each>
	</xsl:if> <!-- inputs ends here -->

	<xsl:comment>if parent's attrib is Outputs, print it!</xsl:comment>
	<xsl:if test="contains(../@name, 'Outputs')">
		<b><p><xsl:value-of select="../@name"/>:</p></b>
	</xsl:if>

</xsl:template>
</xsl:stylesheet>

Is there a way to print a child's attribute value w/o knowing the name of
child? In this case i have to first check if its an HSString then i can
print: <xsl:value-of select="./HSString/@name"/> ??



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread
  • looping
    • Ahsan - Sun, 22 Jun 2003 20:21:44 -0400 (EDT) <=

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.