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

RE: problem matching attribute

Subject: RE: problem matching attribute
From: "Evan Lenz" <evan@xxxxxxxxxxxx>
Date: Mon, 15 Nov 2004 16:10:34 -0800
xsl access attribute of child
Hi Ann Marie,

The problem is that your template rule does not copy the <user> element. It
only tries to add an attribute. I suspect that the XSLT processor is falling
back from an error. It's an error to try to add an attribute to an element
after any child nodes have been added. (In this case, the whitespace-only
text node before each <user> element has been added.) If you first stripped
the whitespace from the source tree, you'd find that the "name" attribute
would get added to the <security-role-mapping> element instead.

You could fix your template rule by wrapping <xsl:copy> around
<xsl:attribute>. But a better, more flexible approach would be to match the
attribute node itself rather than the <user> element:

<xsl:template match="user/@name">
  <xsl:attribute name="{@name}">foo</xsl:attribute>

I'm of course assuming that you have the identity transformation template
rule in your stylesheet which looks like this:

<xsl:template match="@*|node()">
    <xsl:apply-templates select="@*|node()"/>

Hope this helps,

> -----Original Message-----
> From: Ann Marie Rubin [mailto:Annmarie.Rubin@xxxxxxx]
> Sent: Monday, November 15, 2004 3:42 PM
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject:  problem matching attribute
> Hello List,
> If I have xml such as the this:
> 	<namespace-access>
> 		<read-access>
> 			<namespace-resource root="">
> 				<security-role-mapping
> name="consoleadmins" >
>                                    <user name="iasadmin"/>
>                                    <user name="guestadmin"/>
>                                    <group name="admins" />
>                                    <group name= "special" />
>                               </security-role-mapping>
> 			</namespace-resource>
> 		</read-access>
> 		<write-access>
> 			<namespace-resource root="">
> 				<security-role-mapping>
> 					<group
> name="jazn.com/administrators"/>
> 				</security-role-mapping>
> 			</namespace-resource>
> 		</write-access>
> 	</namespace-access>
> I want to update 'name="guestadmin"' to 'name="foo"'
> undre the "consoleadmins" role?
> I tried this:
> <xsl:template
> match="read-access/namespace-resource/security-role-mapping/user">
>  <xsl:attribute name="{name()}">
>  <xsl:value-of select="'foo'"/>
>  </xsl:attribute>
> but got this result:
> read-access>
>                         <namespace-resource root="">
>                                 <security-role-mapping name="">
>                                    <group name=""/>
>                                    <group name=""/>
>                               </security-role-mapping>
>                         </namespace-resource>
>                 </read-access>
> I seem to be matching the wrong node and replacing it with
> blank lines.
> Ann Marie

Current Thread


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.
First Name
Last Name
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.