Subject: RE: problem matching attribute
From: "Evan Lenz" <evan@xxxxxxxxxxxx>
Date: Mon, 15 Nov 2004 16:20:38 -0800
|
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[@name='consoleadmins']/user/@name[.='guestadmin
']">
<xsl:attribute name="name">foo</xsl:attribute>
</xsl:template>
Evan
> -----Original Message-----
> From: Evan Lenz [mailto:evan@xxxxxxxxxxxx]
> Sent: Monday, November 15, 2004 4:11 PM
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: RE: 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="{@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.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
|