Removing an attribute from an element in xsl

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • MedIt
    New Member
    • Feb 2008
    • 15

    Removing an attribute from an element in xsl

    Hi,
    I am new in using xsl.I am stuck in a simple task,which is trying to remove an atribute from a node,and keep the rest of the attributes of this element in the xslt.
    I have tried a couple of options but to no use so far!
    Can any one shed some light on me?
    Here's a sample of my original xml:

    <?xml version="1.0" encoding="UTF-8" ?>
    <dom xmlns="http://www.cdisc.org/ns/odm/v1.2" xmlns:xsi="http ://www.w3.org/2001/XMLSchemainstan ce"
    xsi:schemaLocat ion="http://www.cdisc.org/ns/odm/v1.2 http://www.cdisc.org/schema/odm/v1.2.1/ODM121.xsd"
    CreationDateTim e="20060203T14: 03:06" Granularity="Al l" AsOfDateTime="2 0060203T14:03:1 0">
    /* children node here */

    </dom>

    And I want my transformed xml to be:
    <?xml version="1.0" encoding="UTF-8" ?>
    <dom xmlns="http://www.cdisc.org/ns/odm/v1.2" xmlns:xsi="http ://www.w3.org/2001/XMLSchemainstan ce"
    xsi:schemaLocat ion="http://www.cdisc.org/ns/odm/v1.2 http://www.cdisc.org/schema/odm/v1.2.1/ODM121.xsd"
    CreationDateTim e="20060203T14: 03:06" Granularity="Al l" >
    /* children node here */

    </dom>

    removing the 'AsOfDateTime' attribute of the dom element.
    Thanks your help in advance!

    MedIt
  • jkmyoung
    Recognized Expert Top Contributor
    • Mar 2006
    • 2057

    #2
    AsOfDateTime

    A typical copy template looks like so:
    [code=xml]
    <xsl:template match="*">
    <xsl:copy>
    <xsl:copy-of select="@*">
    <xsl:apply-templates/>
    </xsl:copy>
    </xsl:template>[/code]

    So just change the copy-of to
    <xsl:copy-of select="@*[name() != 'AsOfDateTime']">

    Comment

    • MedIt
      New Member
      • Feb 2008
      • 15

      #3
      Thanks for your help!
      I managed to alter a bit from what you specefied.
      Thanks so much!
      Originally posted by jkmyoung
      AsOfDateTime

      A typical copy template looks like so:
      [code=xml]
      <xsl:template match="*">
      <xsl:copy>
      <xsl:copy-of select="@*">
      <xsl:apply-templates/>
      </xsl:copy>
      </xsl:template>[/code]

      So just change the copy-of to
      <xsl:copy-of select="@*[name() != 'AsOfDateTime']">

      Comment

      Working...