2011-10-11 2 views

답변

1

, 방법 I의 값이 갖는 유형 결정 않는다 즉 그것은 부울, 정수, 이중 또는 문자열?

XML 문서와 관련된 스키마가없는 경우이 유형은 항상 xs:string이고 질문은 그다지 의미가 없습니다.

그러나 올바른 질문은입니다. 이러한 유형 중 어떤 것이 호환 가능합니까? (캐스터 블 가능)?

이 변환은 어떻게 발견되는지를 보여줍니다. 또한 <xsl:next-match>의 우아함과 힘을 보여 원하는 정확한 결과가을 생산

<value>42</value> 

:

42 is castable as xs:string. 42 is castable as xs:integer. 
제공되는 XML 문서
에 적용

<xsl:stylesheet version="2.0" 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    xmlns:xs="http://www.w3.org/2001/XMLSchema"> 
    <xsl:output omit-xml-declaration="yes" indent="yes"/> 

<xsl:template match="text()[. castable as xs:integer]"> 
    <xsl:sequence select="., ' is castable as xs:integer. '"/> 
    <xsl:next-match/> 
</xsl:template> 

<xsl:template match="text()[. castable as xs:boolean]"> 
    <xsl:sequence select="., ' is castable as xs:boolean. '"/> 
    <xsl:next-match/> 
</xsl:template> 

<xsl:template match="text()[. castable as xs:string]"> 
    <xsl:sequence select="., ' is castable as xs:string. '"/> 
    <xsl:next-match/> 
</xsl:template> 

<xsl:template match="text()"/> 
</xsl:stylesheet> 

1

스키마 인식 변환을 사용하는 경우 이 value 요소는 xs : int 유형입니다. - 인스턴스가 유효한 유니온의 멤버 유형 중 첫 번째 유형입니다.

당신이 어떤 유형 테스트 할 경우이 같은 시도 :

<xsl:choose> 
    <xsl:when test=". instance of element(*, xs:int)">int</xsl:when> 
    <xsl:when test=". instance of element(*, xs:boolean)">boolean</xsl:when> 
    etc 
<xsl:choose> 
관련 문제