开发者

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 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜