簡體   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