2015-06-21 141 views
1

我想將XSD屬性@type的值從xsd:boolean更改爲xsd:string如何更改屬性值

我的XSD是

<xsd:element name="Complete" nillable="true" type="xsd:boolean"/> 
<xsd:element name="taskno" nillable="true" type="xsd:integer"/> 

的XSLT我所寫的內容替換所有@type屬性值xsd:string。我無法檢查@type是否爲xsd:boolean

<?xml version="1.0" encoding="ISO-8859-1"?> 
<xsl:stylesheet 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    xmlns:xs="http://www.w3.org/2001/XMLSchema" 
    version="1.0"> 

    <xsl:param name="pNewType" select="'xsd:string'"/> 

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

    <xsl:template match="@type"> 
     <!-- <xsl:if test="type='xsd:boolean'"> 
     Found element!!********* 
     </xsl:if>  --> *** Condition to check if its boolean doesn't work 
     <xsl:attribute name="type"> 
      <xsl:value-of select="$pNewType"/> 
     </xsl:attribute> 
    </xsl:template> 
</xsl:stylesheet> 

回答

1

變化

<xsl:template match="@type"> 

<xsl:template match="@type[ . = 'xsd:boolean']"> 

全部XSLT:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
       xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
       version="1.0"> 

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

    <xsl:template match="@type[ . = 'xsd:boolean']"> 
    <xsl:attribute name="type"> 
     <xsl:value-of select="'xsd:string'"/> 
    </xsl:attribute> 
    </xsl:template> 

</xsl:stylesheet>