2015-06-21 220 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>