[xsl] looping

Subject: [xsl] looping
From: "Ahsan" <ahsan_hussain@xxxxxxxxxxxxx>
Date: Sun, 22 Jun 2003 17:24:42 -0700
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