현재 요소의 값이 특정 유형 (예 : xs : integer)이어야하고 그렇지 않은 경우 예외가 발생한다고 주장하는 좋은 방법이 있습니까? XS의요소 값이 특정 유형임을 주장하는 방법은 무엇입니까?
5 예 : 정수
지정된 값이 지정된 형태의 인스턴스이기 때문에이 예는 true를 돌려 XPath
에서 XSL 2.0
현재 요소의 값이 특정 유형 (예 : xs : integer)이어야하고 그렇지 않은 경우 예외가 발생한다고 주장하는 좋은 방법이 있습니까? XS의요소 값이 특정 유형임을 주장하는 방법은 무엇입니까?
5 예 : 정수
지정된 값이 지정된 형태의 인스턴스이기 때문에이 예는 true를 돌려 XPath
에서 XSL 2.0
을 사용하여 다음과 같이 instance of
을 사용할 수 있습니다 .
자세한 내용은, 당신은 this를 확인할 수 있습니다.
하나는 동적 변수/값의 유형을 판별하는 FXSL 라이브러리 f:type()
함수를 사용할 수있다. 원하는, corect 결과 생성되는
<nums>
<num>01</num>
<num>02</num>
<num>03</num>
<num>04</num>
<num>05</num>
<num>06</num>
<num>07</num>
<num>08</num>
<num>09</num>
<num>10</num>
</nums>
:이 변환이 XML 문서에 적용될 때 여기
는f:type()
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:f="http://fxsl.sf.net/"
exclude-result-prefixes="f xs"
>
<xsl:import href="../f/func-type.xsl"/>
<!-- To be applied on ../data/numList.xml -->
<xsl:output omit-xml-declaration="yes"/>
<xsl:template match="/">
f:apply(f:typeConstructor(11),'03'): <xsl:value-of select="f:apply(f:typeConstructor(11),'03')"/>
f:apply(f:typeConstructor('xxx'),'03'): <xsl:value-of select="f:apply(f:typeConstructor('xxx'),'03')"/>
f:apply(f:typeConstructor(11),'03') gt 4: <xsl:value-of select="f:apply(f:typeConstructor(11),'03') gt 4"/>
f:type(f:apply(f:typeConstructor(11),'03')): <xsl:value-of select="f:type(f:apply(f:typeConstructor(11),'03'))"/>
f:type(f:apply(f:typeConstructor('string'), 3)): <xsl:value-of select="f:type(f:apply(f:typeConstructor('string'),'03'))"/>
<!-- Supported only by a SA Processor -->
xs:token('abc') : <xsl:value-of select="f:type(xs:token('abc'))"
use-when="system-property('xsl:is-schema-aware')='yes'"/>
-1 : <xsl:value-of select="f:type(-1)"/>
<!-- Supported only by a SA Processor -->
xs:negativeInteger(-1) : <xsl:value-of select="f:type(xs:negativeInteger(-1))"
use-when="system-property('xsl:is-schema-aware')='yes'" />
xs:nonPositiveInteger(0) : <xsl:value-of select="f:type(xs:nonPositiveInteger(0))"
use-when="system-property('xsl:is-schema-aware')='yes'" />
0 : <xsl:value-of select="f:type(0)"/>
3 : <xsl:value-of select="f:type(3)"/>
3. : <xsl:value-of select="f:type(3.)"/>
3.0E1 : <xsl:value-of select="f:type(3.0E1)"/>
xs:float(3) : <xsl:value-of select="f:type(xs:float(3))"/>
<!-- Supported only by a SA Processor -->
xs:positiveInteger(3) : <xsl:value-of select="f:type(xs:positiveInteger(3))"
use-when="system-property('xsl:is-schema-aware')='yes'" />
'3' : <xsl:value-of select="f:type('3')"/>
(/*/*/text())[1] : <xsl:value-of select="f:type((/*/*/text())[1])"/>
data((/*/*/text())[1]) : <xsl:value-of select="f:type(data((/*/*/text())[1]))"/>
</xsl:template>
</xsl:stylesheet>
위한 FXSL에서 테스트 변환이다
f:apply(f:typeConstructor(11),'03'): 3
f:apply(f:typeConstructor('xxx'),'03'): 03
f:apply(f:typeConstructor(11),'03') gt 4: false
f:type(f:apply(f:typeConstructor(11),'03')): xs:integer
f:type(f:apply(f:typeConstructor('string'), 3)): xs:string
xs:token('abc') : xs:string
-1 : xs:integer
xs:negativeInteger(-1) : xs:integer
xs:nonPositiveInteger(0) : xs:integer
0 : xs:integer
3 : xs:integer
3. : xs:decimal
3.0E1 : xs:double
xs:float(3) : xs:float
xs:positiveInteger(3) : xs:integer
'3' : xs:string
(/*/*/text())[1] : xml:node
data((/*/*/text())[1]) : xs:string
,210 설명 :
f:type()
, its source에서 알 수있는 바와 같이, 내부적으로는 XPath 2.0 연산자 instance of
를 사용하고 특정 유형을 결정할 때까지 이상의 특정 유형에 가장 일반적인 유형의 값을 테스트한다.
Saxon 9 Enterprise Edition 또는 XmlPrime 또는 AltovaXML과 같은 스키마 인식 XSLT 2.0 프로세서를 사용하면 XSLT로 처리 할 때 입력 문서의 유효성을 검사하는 데 W3C XML 스키마를 사용할 수 있습니다.
가 cast as
연산자를 사용하여, 예를 들어
'5' cast as xs:integer
수익률 5
'foo' cast as xs:integer
은 색슨를 사용하여 Cannot convert string "d" to an integer
가 발생합니다. 당신이 당신의 자신의 오류가 발생하려면
당신은, 예를 들어, castable as
을 사용할 수 있습니다
if (not('foo' castable as xs:integer)) then
error((), 'bad')