简体   繁体   English

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

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

Very simply, is it possible to type an XSLT template or function to return a named sequence constructor? 很简单,是否可以键入XSLT模板或函数以返回命名序列构造函数?

eg in FpML , there is the Product.model group, which simply contains two elements (ProductType and ProductId). 例如在FpML中 ,有一个Product.model组,它仅包含两个元素(ProductType和ProductId)。 I'd like to be able to create a typed template which returns that sequence, but have no idea what the "as" attribute should contain. 我希望能够创建一个返回该序列的类型化模板,但不知道“ as”属性应包含什么。

Update 更新资料

I'll include the relevant bit of the FpML schema for convenience : 为了方便起见,我将包括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>

So, I'd like to be able to type a template as this xsd:group. 因此,我希望能够输入一个模板作为xsd:group。 Is this even possible? 这有可能吗?

The value of the @as should contain an XPATH sequence type @as的值应包含XPATH序列类型

Since you are constructing a sequence of two different types of elements I believe you would use element()* , which would indicate that the template will return zero or more occurrences of an element. 由于您要构造两种不同类型的元素的序列,因此我相信您会使用element()* ,这将指示模板将返回零次或多次出现的元素。

You could type the individual templates/functions used to produce those elements and restrict them to the specific element. 您可以键入用于生成这些元素的单个模板/功能,并将它们限制为特定的元素。 For intance, element(ProductType)? 例如, element(ProductType)? would indicate zero or one ProductType element. 将指示零或一个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>

EDIT: looking over the details for sequence type syntax, the definition of element is: 编辑:查看序列类型语法的详细信息,元素的定义是:

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

The second parameter, type name , is a QName 第二个参数, 类型名称 ,是QName

One of the examples listed under 2.5.3 SequenceType Syntax : 2.5.3 SequenceType语法下列出的示例之一:

element(*, po:address) refers to an element node of any name that has the type annotation po:address (or a type derived from po:address) element(*, po:address)指任何名称的元素节点,其类型注释为po:address(或从po:address派生的类型)

So, you might be able to do the following(but it would probably require a schema aware processor, like Saxon-EE ): 因此,您可能可以执行以下操作(但可能需要使用模式识别处理器,例如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