how 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
andkeyref
seems to be the recommended approach overIDREF
.