• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to remove an attribute from a specific Element

 
Arpit Mehta
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is what is getting generated automatically using one process:

<saml2:Assertion xmlns:saml2="urn:oasis:names:tc:SAML:2.0:assertion" ID="_6e0b628891c999536881cb8dc622ae5c" IssueInstant="2010-05-27T20:40:09.768Z" Version="2.0">
<saml2:Issuer Format="urn:oasis:names:tc:SAML:2.0:nameid-format:entity" >YOUR ISSUER</saml2:Issuer>
<saml2:Subject>
<saml2:NameID Format="urn:oasis:names:tc:SAML:2.0:nameid-format:transient">_b0d2954c37e201e7749fc7bbffde1861</saml2:NameID>
<saml2:SubjectConfirmation Method="urn:oasis:names:tc:SAML:2.0:cm:bearer">
<saml2:SubjectConfirmationData NotBefore="2010-05-27T20:40:09.768Z" NotOnOrAfter="2010-05-27T20:45:09.768Z" />
</saml2:SubjectConfirmation>
</saml2:Subject>
<saml2:Conditions NotBefore="2010-05-27T20:40:09.768Z" NotOnOrAfter="2010-05-27T20:45:09.768Z"> <saml2:AudienceRestriction>
<saml2:Audience>https://fed.adp.com</saml2:Audience>
</saml2:AudienceRestriction>
</saml2:Conditions>
<saml2:AuthnStatement AuthnInstant="2010-05-27T20:40:09.616Z" SessionIndex="e00aafb5ce47bdc443e6562fdcb77feb9deb1e32fe98dbea3b01e307c9ef50b3">
<saml2:SubjectLocality Address="128.148.176.32"/>
<saml2:AuthnContext> <saml2:AuthnContextClassRef>urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport</saml2:AuthnContextClassRef>
</saml2:AuthnContext>
</saml2:AuthnStatement>
<saml2:AttributeStatement>
...............
...............
</saml2:AttributeStatement>
</saml2:Assertion>


We need to remove @NotBefore attribute from saml2:SubjectConfirmationData element and add a new attribute @Recipient. I have the code to add new attribute to specific element but not able to remove attribute from that element

To add new attribute in a specific Element

<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*"/>
<xsl:apply-templates mode="add-atts" select="."/>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>

<!-- By default, don't add any attributes -->
<xsl:template mode="add-atts" match="*"/>

<xsl:template mode="add-atts" match="*[namespace-uri()='urn:oasis:names:tc:SAML:2.0:assertion' and local-name()='SubjectConfirmationData']">
<xsl:attribute name="Recipient">https://fed-stag.adp.com/affwebservices/public/saml2assertionconsumer</xsl:attribute>
</xsl:template>



Mainly we are looking for a code to remove an attribute from a specific Element.
Note : @NotBefore attribute is also present in saml2:Conditions element which should not be removed or changed



I have used a code to remove attribute but it is removing from all the elements where ever it is finding that attribute but i need to remove is from only one element.

To remove the @NotBefore attribute

<xsl:template match="*">
<xsl:copy>
<xsl:apply-templates select="@*"/>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>

<xsl:template match="@*">
<xsl:copy-of select="."/>
</xsl:template>

<xsl:template match="@NotBefore"/>
 
Paul Clapham
Sheriff
Posts: 21322
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Right now you have a template which simply ignores all instances of an attribute, which ensures that no instances of the attribute are written to the output. If you want a template that copies only some instances of an attribute, then you'll have to write that template.

It appears you want to write all instances of that attribute except if the parent of the attribute is... something? Then write that code. I'm sure you already know how to do that, I suspect your confusion is how to code the "... something" part. Am I right? If so then you'll have to describe more clearly what that part is.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic