Usage of ID/IDREFS in XML Schema
how开发者_C百科 should I use ID/IDREFS within XMLSchema in order to use it for XSL transformation with xsl:key and xpath functions key() and id() ?
If I use the following DTD all is fine
<!ELEMENT role EMPTY>
<!ATTLIST role
name ID #REQUIRED>
<!ELEMENT usecases (usecase)+>
<!ELEMENT usecase EMPTY>
<!ATTLIST usecase
roles IDREFS #REQUIRED
name CDATA #REQUIRED>
I can define the xsl:key and use key() and id() XPath functions successfully
<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>
But if I migrate my DTD into XMLSchema, the same XSL transformation produce just an empty document.
<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>
Or is this whole approach with the usage of ID/IDREFS wrong and I have to change it to XML Key ? But thats a lot of migration, because there aren't such things like XML keyrefs, isn't it ?
Kind regards Dominik
I have not used this feature yet, but according to Defining Keys & their References, using key
and keyref
seems to be the recommended approach over 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 thepNumKey
key. This declaration ofnumber
as akeyref
does not mean that its value must be unique, but it does mean there must exist apNumKey
with the same value.
精彩评论