gpt4 book ai didi

xslt - ID/IDREFS 在 XML Schema 中的使用

转载 作者:行者123 更新时间:2023-12-04 19:57:12 24 4
gpt4 key购买 nike

我应该如何在 XMLSchema 中使用 ID/IDREFS,以便通过 xsl:key 和 xpath 函数 key() 和 id() 将它用于 XSL 转换?

如果我使用下面的 DTD 一切都很好

<!ELEMENT role EMPTY>
<!ATTLIST role
name ID #REQUIRED>
<!ELEMENT usecases (usecase)+>
<!ELEMENT usecase EMPTY>
<!ATTLIST usecase
roles IDREFS #REQUIRED
name CDATA #REQUIRED>

我可以定义 xsl:key 并成功使用 key() 和 id() XPath 函数

<xsl:key name="usecase2role" match="usecase" use="id(@roles)/@name" />
<xsl:template match="role">
<xsl:apply-templates select="key('usecase2role', @name)" mode="byrole">
<xsl:with-param name="roleName" select="@name"/>
</xsl:apply-templates>
</xsl:template>
<xsl:template match="usecase" mode="byrole">
<xsl:param name="roleName"/>
insert into permission(roleId, usecaseId) values (<xsl:value-of select="$roleName"/>, <xsl:value-of select="@name"/>);
</xsl:template>

但是如果我将我的 DTD 迁移到 XMLSchema,相同的 XSL 转换只会生成一个空文档。

<xsd:complexType name="role">
<xsd:attribute name="name" type="xsd:ID" use="required"/>
</xsd:complexType>
<xsd:complexType name="usecase">
<xsd:attribute name="name" use="required"/>
<xsd:attribute name="roles" use="required" type="xsd:IDREFS"/>
</xsd:complexType>

或者整个使用 ID/IDREFS 的方法是错误的,我必须将其更改为 XML Key 吗?但那是很多迁移,因为没有像 XML keyrefs 这样的东西,不是吗?

亲切的问候多米尼克

最佳答案

我还没有使用过这个功能,但是根据Defining Keys & their References , 使用 keykeyref似乎是关于 IDREF 的推荐方法.

To ensure that the part-quantity elements have corresponding part descriptions, we say that the number attribute ( <field xpath="@number"/>) of those elements ( <selector xpath="r:regions/r:zip/r:part"/>) must reference the pNumKey key. This declaration of number as a keyref does not mean that its value must be unique, but it does mean there must exist a pNumKey with the same value.

关于xslt - ID/IDREFS 在 XML Schema 中的使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5755281/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com