Quick correction. That should have been:
<xsl:template match="user/@name">
<xsl:attribute name="name">foo</xsl:attribute>
</xsl:template>
Also, a more restricted update in line with what you said you want:
I want to update 'name="guestadmin"' to 'name="foo"'
undre the "consoleadmins" role?
...would look like this:
<xsl:template
match="security-role-mapping[(_at_)name='consoleadmins']/user/@name[.='guestadmin
']">
<xsl:attribute name="name">foo</xsl:attribute>
</xsl:template>
Evan
-----Original Message-----
From: Evan Lenz [mailto:evan(_at_)evanlenz(_dot_)net]
Sent: Monday, November 15, 2004 4:11 PM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: RE: [xsl] problem matching attribute
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="{(_at_)name}">foo</xsl:attribute>
</xsl:template>
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:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
Hope this helps,
Evan
-----Original Message-----
From: Ann Marie Rubin [mailto:Annmarie(_dot_)Rubin(_at_)Sun(_dot_)COM]
Sent: Monday, November 15, 2004 3:42 PM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] 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
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--