2011-11-30 38 views
2

我在XML模式中有組定義。像這樣:在XSL轉換中使用XML模式組

<attributeGroup name="my_attributes"> 
    <attribute ref="ns:foo" /> 
    <attribute ref="ns:bar" /> 
</attributeGroup> 

此外,我有一個XML轉換,我希望能夠重用這些定義。是否可以創建一個匹配這樣的組的模板?事情是這樣的,也許:

<xsl:template matchGroup="my_attributes"> 
    <foobar> 
     <xsl:copy-of select="@*"/> 
     <xsl:value-of select="." /> 
    </foobar> 
</xsl:template> 

回答

1

是否有可能建立一個滿足這樣一組模板? 事情是這樣的,也許:

<xsl:template matchGroup="my_attributes"> 
    <foobar> 
     <xsl:copy-of select="@*"/> 
     <xsl:value-of select="." /> 
    </foobar> 
</xsl:template> 

沒有,XSLT <xsl:template>指令沒有一個matchGroup屬性和 任何符合XSLT處理器必須提高一個語法錯誤,因爲這個原因

像這樣的事情是可能接近你正在尋找:

<xsl:template match="@ns:foo[../@ns:bar]"> 
<!-- Processing here --> 
</xsl:template> 

匹配模式的上述含義:

如同local-name()foo即在任何屬性與前綴"ns:"相關聯的名稱空間,以及其「」「父母」(這個屬性附加的屬性) *還有另一個名爲* ns:bar的屬性。

+0

「@ns:foo [../@ns:bar]」是什麼意思? – Alp

+0

@Alp:我用你要求的解釋更新了答案。 –

+0

謝謝你的解釋,但那不是我故意需要的。 XSD中的attributeGroup表示允許任何屬性,它們不必一次全部出現(忽略父項)。 – Alp