This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Axis problem
- To: XSL-List at mulberrytech dot com
- Subject: Axis problem
- From: Juergen Baier <x_baier at propack-data dot com>
- Date: Thu, 07 Sep 2000 12:51:05 +0200
- Organization: Propack Data GmbH
- Reply-To: xsl-list at mulberrytech dot com
Hi,
I'm a XSLT beginner and I recently run into a problem. I couldn't find
an example where my problem is explained (probably I just didn't see it
in the FAQs).
I have a XML source like this:
<component class="someClass" name="myName">
<properties>
<property name="someProperty" type="someType">
<specialProperty name="someSpecialProperty"/>
</property>
<property name="otherProperty" type="otherType">
<otherSpecialProperty name="someOtherSpecialProperty/>
</property>
<!-- many other properties -->
</properties>
</component>
<!-- some other components ...-->
I have written a stylesheet:
<xsl:template match="component">
<xsl:choose>
<xsl:when test="@class = 'someClass'">
<xsl:choose>
<xsl:when test="properties/property/@type = 'someType'">
someClass name: <xsl:value-of select="@name"/>
, property name: <xsl:value-of
select="properties/property/someProperty/@name"/>
, specialProperty name: <xsl:value-of
select="properties/property/someProperty/specialProperty/@name">
<!-- do some special things ... -->
</xsl:when>
<!-- some other whens -->
</xsl:choose>
</xsl:when>
</xsl:choose>
</xsl:template>
which correctly prints out the name of component and the name of a
special type of property.
But: different classes often have the same properties. So instead of
checking the property type inside the <xsl:when test="@class =
'someClass'>..</xsl:when> I want a more generic approach, like this:
<xsl:template match="properties">
<xsl:for-each select="property">
<xsl:choose>
<xsl:when test="@type = 'someType'">
someClass name: <xsl:value-of select="XXXXX"/>
, property name: <xsl:value-of select="@name"/>
, specialProperty name: <xsl:value-of
select="specialProperty/@name"/>"
</xsl:when>
</xsl:choose>
</xsl:for-each>
</xsl:template>
The output should be:
someClass name: myName, property name: someProperty, specialProperty
name: someSpecialProperty
otherClass name: myName, property name: someOtherProperty,
specialProperty name: someOtherSpecialProperty
someClass name: myName2, property name: someProperty, specialProperty
name: someSpecialProperty
Instead of the XXXXX I tried several XPath-Expressions (parent,
ancestor, ...), but I never get the @name of the component which
properties I am processing now. The other stuff (propertyName and
specialPropertyName) works correctly.
Hmm. Hope that was not too confusing ...
If you've any idea what I'm doing wrong, please give me a hint.
Thanks a lot,
Juergen
--
Juergen Baier
x_baier@propack-data.com
Propack Data GmbH
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list