Forum Moderators: open

Message Too Old, No Replies

XSL Newbie: Attributes are GREEDY?

How can I make my XSL attributes non-greedy?

         

jazzcat

6:23 pm on Apr 12, 2007 (gmt 0)

10+ Year Member



Howdy all,

I have some XML that I'm trying to represent in a Sharepoint service via XSL. The problem is, this statement:

<xsl:value-of select="//Collaboration[@name]"/>

...grabs every object where there is an attribute called Name. All I want is to grab the *name* attribute from the root object (which happens to be called Collaboration).

In the example below, when viewing in IE the resulting webpage would print this string:

true Main

because it seems to be grabbing elements from the ExampleObject aggregate which has the attribute "Name". Note that it would _not_ grab the root element which also has the attribute "Name". (Note that Mozilla throws an XML Parser error...)

XML snippet:

<Collaboration name="ClaimRegistration_CSAA_Sync_SL_MfToCS_Sync" type="Collaboration">
<ExampleObject name="Bob">
<translator:subscribesEvents>true</translator:subscribesEvents>
<Translator:appSpecificInfo/>
<translator:scenarioName>Main</translator:scenarioName>
</ExampleObject>
</Collaboration>

XSL snippet:

<HTML>
<HEAD>
<TITLE>Collaboration: <xsl:value-of select="//Collaboration[@name]"/></TITLE>
</HEAD>
<BODY>
<h1>Collaboration: <xsl:value-of select="//Collaboration[@name]" /></h1>
</BODY>
</HTML

cmarshall

6:53 pm on Apr 12, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm pretty sure that's exactly how it's supposed to work. I'm not [yet] experienced enough in XSLT to answer the question expertly, but I'm sure there's an XPath answer. I would suggest filtering for the name, and doing an xsl:apply-templates on that.

jazzcat

8:15 pm on Apr 12, 2007 (gmt 0)

10+ Year Member



After perusing some of the XSLT reference, I think I found the problem. When I do this:

<xsl:value-of select="//Collaboration[@name]"/>

It selects the whole element, //Collaboration, because it has a name attribute. I need to find a way to select the value of the name attribute itself.

cmarshall

8:26 pm on Apr 12, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Here's [w3.org] something I just found. I don't have time to track it down, but you can definitely get this in XPath.