开发者

XSLT selected value datatype

开发者 https://www.devze.com 2023-04-05 16:11 出处:网络
How do I check th开发者_JAVA技巧e type of selected value in XSLT.I am trying to validate my XML against and XSD and if the value if is of real type , then I will add the nodeXSLT 2.0 allows you to val

How do I check th开发者_JAVA技巧e type of selected value in XSLT.I am trying to validate my XML against and XSD and if the value if is of real type , then I will add the node


XSLT 2.0 allows you to validate an element (including a newly constructed element) against a schema, for example

<xsl:import-schema namespace="abc.xyz" schema-location="file://temp.xsd"/>

<xsl:template ...>
   <xsl:element name="x" validation="strict">
     ...
   </xsl:element>
</xsl:template>

Unfortunately there's no way of catching the error if it's invalid. However, Saxon has a try/catch extension for doing this.


How do I check the type of selected value in XSLT?

An XSLT 2.0 Schema-aware (SA) processor can validate against a schema source XML files, output result files, intermediary trees, parameters and variable values, return values from functions or from applying/calling templates.

XSLT 1.0 uses XPath 1.0 which is not strongly typed and has only a few standard types.

I am trying to validate my XML against and XSD and if the value if is of real type , then I will add the node

This is much easier than validating against a schema.

In XPath 2.0 (XSLT 2.0) use:

$yourVar instance of xs:double

In XPath 1.0 (XSLT 1.0) use:

number($yourVar) = number($yourVar)
0

精彩评论

暂无评论...
验证码 换一张
取 消