2009-06-17 5 views
0

사용중인 여러 네임 스페이스와 유효성을 검사 할 스키마가있는 XML 문서가 있습니다. 스키마는 모든 요소가 "규정 된"것을 요구하며, 이것이 null 네임 스페이스없이 완전한 QName을 가져야 함을 의미한다고 가정합니다.기본 네임 스페이스가있는 노드 선택

그러나이 거대한 XML 문서의 일부 요소는 기본 네임 스페이스를 사용하여 빠져 있으며이 네임 스페이스는 비어 있습니다. Natually, 그들은 스키마와 함께 검증에 실패합니다.

나는 네임 스페이스가없는 노드를 선택하고 다른 노드와 같은 접두사를 가진 특정 노드를 지정할 XSLT를 작성하려고합니다. 예를 들어 :

<x:doc xmlns:x="http://thisns.com/"> 
    <x:node @x:property="true"> 
    this part passes validation 
    </x:node> 
    <node property="false"> 
    this part does not pass validation 
    </node> 
</x:doc> 

나는 문서의 루트 노드에 xmlns="http://thisns.com/"을 추가하는 시도했지만,이 스키마 검증에 동의하지 않습니다. 내가 어떻게이 일을 할 수 있는지에 대한 생각?

감사합니다.

답변

2
<!-- Identity transform by default --> 
<xsl:template match="node() | @*"> 
    <xsl:copy> 
    <xsl:apply-templates select="node() | @*"/> 
    </xsl:copy> 
</xsl:template> 
<!-- Override identity transform for elements with blank namespace --> 
<xsl:template match="*[namespace-uri() = '']">  
    <xsl:element name="{local-name()}" namespace="http://thisns.com/"> 
    <xsl:apply-templates select="node() | @*"/> 
    </xsl:element> 
</xsl:template> 
<!-- Override identity transform for attributes with blank namespace --> 
<xsl:template match="@*[namespace-uri() = '']"> 
    <xsl:attribute name="{local-name()}" namespace="http://thisns.com/"><xsl:value-of select="."/></xsl:attribute> 
</xsl:template> 

이 유사한 결과를 줄 것이다 : 두 번째 < 노드 > 네임 스페이스 접두사없이 여전히 것을

<x:doc xmlns:x="http://thisns.com/"> 
    <x:node x:property="true"> 
    this part passes validation 
    </x:node> 
    <node xp_0:property="false" xmlns="http://thisns.com/" xmlns:xp_0="http://thisns.com/"> 
    this part does not pass validation 
    </node> 
</x:doc> 

참고하지만, 지금 때문에 XMLNS의 같은 네임 스페이스의 일부로 간주됩니다 = 속성.

관련 문제