2015-06-21 3 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> 
Смежные вопросы