8

Changing the value of the xml attribute via xsl

 2 years ago
source link: https://www.codesd.com/item/changing-the-value-of-the-xml-attribute-via-xsl.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Changing the value of the xml attribute via xsl

advertisements

I have a following xml document:

<xjdf:XJDF>
 <xjdf:AuditPool>
  <xjdf:Created TimeStamp="2013-09-03T12:07:16+02:00">
   <xjdf:Employee PersonalID="j.smith" Roles="Operator"/>
  </xjdf:Created>
 </xjdf:AuditPool>
</xjdf:XJDF>

In this document I would like to change the value of the TimeStamp attribute of the xjdf:Created element to be empty, like TimeStamp="". How can I do this using xsl? I tried following:

<xsl:template match="//xjdf:XJDF/xjdf:AuditPool/xjdf:Created/@TimeStamp">
    <xsl:attribute name="TimeStamp"/>
</xsl:template>

but without success.


You are not using xsl:attribute the right way, you must always put in an output element declaration (or there's something missing in the XSL you provide us). Moreover, you do not set any new value to the attribute.

Something like that should work

  <xsl:template match="//xjdf:XJDF/xjdf:AuditPool/xjdf:Created">
    <xjdf:Created>
      <xsl:attribute name="TimeStamp">
         (...the new attribute value here...)
      </xsl:attribute>
      <xsl:attribute name=" other_attribute ">
         (...the other attribute value here...)
      </xsl:attribute>

      <xsl:apply-templates />
    </xjdf:Created>
  </xsl:template>


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK