繁体   English   中英

键入XSLT模板/函数作为序列构造函数?

[英]Typing an XSLT template/function as a sequence constructor?

很简单,是否可以键入XSLT模板或函数以返回命名序列构造函数?

例如在FpML中 ,有一个Product.model组,它仅包含两个元素(ProductType和ProductId)。 我希望能够创建一个返回该序列的类型化模板,但不知道“ as”属性应包含什么。

更新资料

为了方便起见,我将包括FpML模式的相关部分:

<xsd:group name="Product.model">
<xsd:sequence>
  <xsd:element name="productType" type="ProductType" minOccurs="0" maxOccurs="unbounded">
    <xsd:annotation>
      <xsd:documentation xml:lang="en">A classification of the type of product. FpML defines a simple product categorization using a coding scheme.</xsd:documentation>
    </xsd:annotation>
  </xsd:element>
  <xsd:element name="productId" type="ProductId" minOccurs="0" maxOccurs="unbounded">
    <xsd:annotation>
      <xsd:documentation xml:lang="en">A product reference identifier allocated by a party. FpML does not define the domain values associated with this element. Note that the domain values for this element are not strictly an enumerated list.</xsd:documentation>
    </xsd:annotation>
  </xsd:element>
</xsd:sequence>

因此,我希望能够输入一个模板作为xsd:group。 这有可能吗?

@as的值应包含XPATH序列类型

由于您要构造两种不同类型的元素的序列,因此我相信您会使用element()* ,这将指示模板将返回零次或多次出现的元素。

您可以键入用于生成这些元素的单个模板/功能,并将它们限制为特定的元素。 例如, element(ProductType)? 将指示零或一个ProductType元素。

<xsl:template name="ProductModel" as="element()*">
  <xsl:call-template name="ProductType" />
  <xsl:call-template name="ProductId" />
</xsl:template>

<xsl:template name="ProductType" as="element(ProductType)?">
  <ProductType></ProductType>
</xsl:template>

<xsl:template name="ProductId" as="element(ProductId)?">
  <ProductId></ProductId>
</xsl:template>

编辑:查看序列类型语法的详细信息,元素的定义是:

ElementTest :: =“ element”“(”(ElementNameOrWildcard(“,” TypeName“?”?)?)?“)”

第二个参数, 类型名称 ,是QName

2.5.3 SequenceType语法下列出的示例之一:

element(*, po:address)指任何名称的元素节点,其类型注释为po:address(或从po:address派生的类型)

因此,您可能可以执行以下操作(但可能需要使用模式识别处理器,例如Saxon-EE ):

<xsl:template name="ProductModel" as="element(*,fpml:Product.model)*">
  <xsl:call-template name="ProductType" />
  <xsl:call-template name="ProductId" />
</xsl:template>

<xsl:template name="ProductType" as="element(ProductType)?">
  <ProductType></ProductType>
</xsl:template>

<xsl:template name="ProductId" as="element(ProductId)?">
  <ProductId></ProductId>
</xsl:template>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM