2016-10-22 4 views
0

Lassen Sie uns sagen, dass wir diese Quelle XML haben:XSLT ändern Attributwert

<?xml version="1.0" encoding="UTF-8"?> 
<SyncSupplierPartyMaster xmlns="http://schema.infor.com/InforOAGIS/2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://schema.infor.com/InforOAGIS/2 http://schema.infor.com/2.10.x/InforOAGIS/BODs/Developer/SyncSupplierPartyMaster.xsd" releaseID="9.2" versionID="2.10.x"> 
    <DataArea> 
     <SupplierPartyMaster> 
      <Classification> 
       <Codes> 
        <Code listID="CLASS" sequence="1">3</Code> 
        <Code listID="CURRENCY" sequence="2">EUR</Code> 
        <Code listID="KVK" sequence="3">-</Code> 
       </Codes> 
      </Classification> 
     </SupplierPartyMaster> 
    </DataArea> 
</SyncSupplierPartyMaster> 

Ich brauche CLASS zu MROClass ändern. Ich habe diese XSL, die nicht funktioniert, kann jemand bitte beraten, was falsch ist? Die Transformation kann auch gefunden werden: http://xsltransform.net/gWEamL8/1

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:my="http://schema.infor.com/InforOAGIS/2"> 
    <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" /> 

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

<!-- Rename attribute Class to MROClass --> 


<xsl:template match="@ListID[.='CLASS']"> 
    <xsl:attribute name="ListID"> 
     <xsl:value-of select="'MROClass'"/> 
    </xsl:attribute> 
</xsl:template> 

</xsl:stylesheet> 

Antwort

1

XSLT ist case-sensitive. Ihre XML-Attribute und listID, aber Ihr XSLT sucht nach ListID (mit einem Großbuchstaben L). Versuchen Sie, die Vorlage zu diesem Wechsel:

<xsl:template match="@listID[.='CLASS']"> 
    <xsl:attribute name="listID"> 
     <xsl:value-of select="'MROClass'"/> 
    </xsl:attribute> 
</xsl:template> 

Beachten Sie, dass Sie nicht wirklich mit xsl:value-of zur Ausgabe von Text benötigen, können Sie dies tun ...

<xsl:template match="@listID[.='CLASS']"> 
    <xsl:attribute name="listID"> 
     <xsl:text>MROClass</xsl:text> 
    </xsl:attribute> 
</xsl:template> 

oder auch nur diese:

<xsl:template match="@listID[.='CLASS']"> 
    <xsl:attribute name="listID">MROClass</xsl:attribute> 
</xsl:template> 
Verwandte Themen