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

selecting elements depending on existence of attribute

Subject: selecting elements depending on existence of attributes
From: Sebastian Schirmer <schirmer@xxxxxxxxxxxxx>
Date: Thu, 3 May 2001 17:03:31 +0200
env entry name
Hello!

I have a XML file that looks like this:


--- snippet xml_to_jsp_include_02.xml ---
<properties>
	<env-entry>
		<env-entry-name cols="2">Name1</env-entry-name>
		<env-entry-type>java.lang.String</env-entry-type>
		<env-entry-value>
			some Content 1
		</env-entry-value>
	</env-entry>
	<env-entry>
		<env-entry-name cols="3">Name1</env-entry-name>
		<env-entry-type>java.lang.String</env-entry-type>
		<env-entry-value>
			some Content 2
		</env-entry-value>
	</env-entry>
	<env-entry>
		<env-entry-name>Name3</env-entry-name>
		<env-entry-type>java.lang.String</env-entry-type>
		<env-entry-value>
			some Content 3
		</env-entry-value>
	</env-entry>	
</properties>
--- snippet ---


There are some env-entry-name elements that have an attribute cols, some do
not. If they have such an attribute, there could exist more than one
env-entry-name elements with the same name as content.
 
Now I want to include the different env-entry-value contents depending of
the env-entry-name element cols attribute value, if there is not such an
attribute, i.e. like in the third env-entry, the default content of
env-entry-value should be included.



My XSL looks like this at the moment:

--- snip ---
<xsl:template name="include">
	<xsl:param name="key" />
	<xsl:variable name="includefile"
select="document('c:/dev/fbs/application/web/layouts/xml_to_jsp_include_02.x
ml')" />	
	<xsl:value-of
select="$includefile/properties/env-entry/env-entry-value[preceding-sibling:
:env-entry-name = $key and preceding-sibling::env-entry-name[@cols =
$cols]]" disable-output-escaping="yes" />
</xsl:template>	
--- snip  ---


where the $key variable is passed like "Name1", the $cols variable is
defined as a top level variable.

Here I have the problem that if an env-entry-name element has no cols
attribute, the depending content is not included. So I have to check if
there is an attribute or not, if not include the default content, if yes
include the specific content that fit to the cols attribute value.




Sebastian Schirmer

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


Current Thread

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.