Tecnologías XML / XSLT / Recetario XSLT / Recetas para aplicaciones XSLT verticales / Generar topic maps XTM desde UML mediante XMI
(Extracto de «XSLT Kochbuch» de Sal Mangano)
Problema
Quiere crear topic maps XTM con su herramienta UML compatible con XMI.
Solución
Si no conoce topic maps, lea la discusión antes de la solución.
UML no se diseñó para topic maps; este ejemplo exige convenciones, sobre todo estereotipos UML especiales. Un estereotipo asocia un identificador con un símbolo de semántica personalizada. Use los de esta tabla:
Tabla: Convenciones UML para topic maps.
Estereotipo | Contexto UML | Significado |
| Clase | Representa un topic. Opcional porque es el papel predeterminado de una clase. |
| Clase | Modela un indicador de sujeto, identificando la clase como sujeto al ser destino de un |
| Clase | Representa un recurso destino de una relación de ocurrencia. |
| Clase | Modela un nombre alternativo, lo que implica ámbito. Los miembros del ámbito se asocian a la clase |
| Asociación | Apunta a un recurso que es una ocurrencia del topic. |
| Asociación | Indica el ámbito de la característica del topic map. Su naturaleza depende del estereotipo de destino ( |
| Asociación de generalización y clase | Una generalización de estereotipo |
Otras correspondencias UML:
- Clase UML
Modela un topic salvo si tiene un estereotipo distinto de
topic. El nombre de clase nombra el topic. Si tiene un atributo llamadoID, su valor predeterminado es el ID; si no, el nombre de clase también es el ID.- Asociación UML
Modela una asociación salvo indicación contraria. Los nombres de asociación y roles UML pasan a la topic map.
- Asociación de instanciación UML
Modela la relación
instanceOfde la topic map.- Generalización UML sin decoración (herencia)
Abreviatura de la relación canónica
superclass-subclasscuyos roles son automáticamentesuperclassysubclass. También enlaza clases de estereotipobaseNamea topics que nombran en otros ámbitos. Generalizaciones de estereotipovarianttambién identifican variantes.
Nota:
Si Rational Rose no guarda XMI, descargue la extensión XMI o RoseXMI. Solo se probó Rose, pero otras herramientas XMI, como Together Control Center de TogetherSoft, deberían funcionar.
Sigue la hoja XMI-XTM. Varias entidades simplifican los nombres XMI largos:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xslt [
<!--= = = = = = = = = = = = = = = = = = = = = = = = = = =-->
<!-- XMI-Organisationsstrukturen auf oberer Ebene -->
<!--= = = = = = = = = = = = = = = = = = = = = = = = = = =-->
<!ENTITY FC "Foundation.Core">
<!ENTITY FX "Foundation.Extension_Mechanisms">
<!ENTITY FD "Foundation.Data_Types">
<!ENTITY MM "Model_Management.Model">
<!ENTITY ME "&FC;.ModelElement">
<!--= = = = = = = = = = = = = = = = = = = = = = = = = = =-->
<!-- Abkürzungen für Grundelemente von XMI-Dateien, die für dieses Stylesheet von besonderem Interesse sind. -->
<!--= = = = = = = = = = = = = = = = = = = = = = = = = = =-->
<!-- Einige generische UML-Elemente -->
<!ENTITY ELEM "&FC;.Namespace.ownedElement">
<!-- Die Assoziation als Ganzes -->
<!ENTITY ASSOC "&FC;.Association">
<!-- Der Verbindungsteil der Assoziation -->
<!ENTITY CONN "&ASSOC;.connection">
<!-- Die Enden der Assoziation. -->
<!ENTITY END "&ASSOC;End">
<!ENTITY CONNEND "&CONN;/&END;">
<!ENTITY ENDTYPE "&END;.type">
<!-- Eine UML-Klasse -->
<!ENTITY CLASS "&FC;.Class">
<!-- Der Name eines UML-Entitys -->
<!ENTITY NAME "&FC;.ModelElement.name">
<!-- Ein UML-Sterotyp -->
<!ENTITY STEREOTYPE "&ME;.stereotype/&FX;.Stereotype">
<!-- Der Ort, an dem UML-Dokumentation in XMI gespeichert wird, die wir für Ressourcendaten benutzen -->
<!ENTITY TAGGEDVALUE "&ME;.taggedValue/&FX;.TaggedValue/&FX;.TaggedValue.value">
<!-- Eine Supertyp-Relation (Vererbung) -->
<!ENTITY SUPERTYPE "&FC;.Generalization.supertype">
<!ENTITY SUBTYPE "&FC;.Generalization.subtype">
<!ENTITY SUPPLIER "&FC;.Dependency.supplier">
<!ENTITY CLIENT "&FC;.Dependency.client">
<!ENTITY DEPENDENCY "/XMI/XMI.content/&MM;/&ELEM;/&FC;.Dependency">
<!ENTITY EXPRBODY "&FC;.Attribute.initialValue/&FD;.Expression/&FD;.Expression.body">
<!ENTITY ATTR "&CLASS;ifier.feature/&FC;.Attribute">
<!-- Wird benutzt, um auf Standard-XTM-PSIs zu zeigen -->
<!ENTITY TM.ORG "http://www.topicmaps.org/xtm/index.html">
]>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xtm="http://www.topicmaps.org/xtm/1.0" xmlns:xlink="http://www.w3.org/1999/xlink">
<xsl:param name="termOnErr" select="true( )"/>
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>Las claves simplifican identificar estereotipos y recorrer asociaciones que referencian atributos xmi.id y xmi.idref:
<!-- Indexklassen nach ihren Namen -->
<xsl:key name="classKey" match="&CLASS;" use="@xmi.id"/>
<!-- Indexstereotypen nach Namen und xmi.id -->
<xsl:key name="stereotypeKey" match="&FX;.Stereotype" use="@xmi.id"/>
<xsl:key name="stereotypeKey" match="&FX;.Stereotype" use="&NAME;"/>
<!-- Die xmi.ids von Stereotypen haben bisher Topic Maps in UML kodiert. Wir benutzen sie hier als effizientes Mittel, um zu überprüfen, ob ein Sterotyp an ein Element angehängt ist. -->
<xsl:variable name="OCCURRENCE_ID" select="key('stereotypeKey','occurrence')/@xmi.id"/>
<xsl:variable name="RESOURCE_ID" select="key('stereotypeKey','resource')/@xmi.id"/>
<xsl:variable name="TOPIC_ID" select="key('stereotypeKey','topic')/@xmi.id"/>
<xsl:variable name="SUBJECT_ID" select="key('stereotypeKey','subject')/@xmi.id"/>
<xsl:variable name="BASENAME_ID" select="key('stereotypeKey','baseName')/@xmi.id"/>
<xsl:variable name="SCOPE_ID" select="key('stereotypeKey','scope')/@xmi.id"/>
<xsl:variable name="VARIANT_ID" select="key('stereotypeKey','variant')/@xmi.id"/>La conversión tiene dos pasadas: topics de clases y asociaciones XTM de UML.
<xsl:template match="/">
<xtm:topicMap>
<xsl:apply-templates mode="topics"/>
<xsl:apply-templates mode="associations"/>
</xtm:topicMap>
</xsl:template>Solo clases sin estereotipo o con estereotipo topic se convierten en topics. Las demás representan indicadores y recursos referenciados:
<!--= = = = = = = = = = = = = = = = = = = = = = =-->
<!-- Übersetzung von UML-Klassen nach TOPICS -->
<!--= = = = = = = = = = = = = = = = = = = = = = =-->
<xsl:template match="&ELEM;/&CLASS;" mode="topics">
<!-- Topics werden als Klassen modelliert, deren Stereotyp entweder leer oder gleich 'topic' ist. -->
<xsl:if test="not(&STEREOTYPE;/@xmi.idref) or &STEREOTYPE;/@xmi.idref = $TOPIC_ID">
<xsl:variable name="topicId">
<xsl:call-template name="getTopicId">
<xsl:with-param name="class" select="."/>
<xsl:with-param name="prefix" select="''"/>
</xsl:call-template>
</xsl:variable>
<xtm:topic id="{$topicId}">
<!-- Dieses for-each dient allein dazu, den Kontext zu dem optionalen Attribut Core.Attribute namens 'subjectIdentityid' zu wechseln. -->
<xsl:for-each select="&ATTR;[&NAME; = 'subjectIdentity']">
<xtm:subjectIdentity>
<xtm:subjectIndicatorRef xlink:href="{&EXPRBODY;}"/>
</xtm:subjectIdentity>
</xsl:for-each>
<xtm:baseName>
<xtm:baseNameString>
<xsl:value-of select="&NAME;"/>
</xtm:baseNameString>
</xtm:baseName>
<xsl:apply-templates select="." mode="getAlternateBaseNames"/>
<xsl:apply-templates select="." mode="getVariants"/>
<xsl:apply-templates select="." mode="getInstanceOf">
<xsl:with-param name="classId" select="@xmi.id"/>
</xsl:apply-templates>
<xsl:apply-templates select="." mode="getOccurrences"/>
</xtm:topic>
</xsl:if>
</xsl:template>
<!-- Gibt die Topic-ID einer Topic-Klasse zurück, die deren id-Attributwert oder Name ist. -->
<xsl:template name="getTopicId">
<xsl:param name="class"/>
<xsl:param name="prefix" select="'#'"/>
<xsl:for-each select="$class">
<xsl:choose>
<xsl:when test="&ATTR;/&NAME; = 'id' ">
<xsl:value-of select="&ATTR;[&NAME; = 'id']/&EXPRBODY;"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="concat($prefix,&NAME;)"/>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:template>
<!-- Gibt die Aussagegegenstands-ID der Aussagegegenstandsklasse zurück, die aus ihrem subjectIdentity-Attributwert oder Namen besteht. -->
<xsl:template name="getSubjectIdentity">
<xsl:param name="class"/>
<xsl:for-each select="$class">
<xsl:choose>
<xsl:when test="&ATTR;/&NAME; = 'subjectIdentity' ">
<xsl:value-of select="&ATTR;[&NAME; = 'subjectIdentity']&EXPRBODY;"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="concat('#',&NAME;)"/>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:template>
<!-- Gibt die Ressourcen-ID einer Ressourcenklasse zurück, die aus ihrem resourceName-Attributwert oder Namen besteht. -->
<xsl:template name="getResourceIdentity">
<xsl:param name="class"/>
<xsl:for-each select="$class">
<xsl:choose>
<xsl:when test="&ATTR;/&NAME; = 'resourceName' ">
<xsl:value-of select="&ATTR;[&NAME; = 'resourceName']/&EXPRBODY;"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="concat('#',&NAME;)"/>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:template>Los nombres alternativos y variantes especializan la clase base mediante generalización UML. Natural o abusivo, funciona y aporta pistas visuales además de estereotipos:
<!-- Alternative Benennungen werden durch die Traversierung von UML-Generalisierungsrelationen und die Suche nach baseName-Stereotypen gefunden. -->
<xsl:template match="&ELEM;/&CLASS;" mode="getAlternateBaseNames">
<xsl:variable name="xmiId" select="@xmi.id"/>
<xsl:for-each select="../&FC;.Generalization [&SUPERTYPE;/&CLASS;/@xmi.idref = $xmiId]">
<xsl:variable name="subtypeXmiId" select="&FC;.Generalization.subtype/&CLASS;/@xmi.idref"/>
<xsl:variable name="class" select="key('classKey',$subtypeXmiId)"/>
<xsl:if test="$class/&STEREOTYPE;/@xmi.idref = $BASENAME_ID">
<xsl:variable name="name" select="$class/&NAME;"/>
<xtm:baseName>
<xsl:call-template name="getScope">
<xsl:with-param name="class" select="$class"/>
</xsl:call-template>
<xtm:baseNameString>
<xsl:value-of select="substring-after($name,'::')"/>
</xtm:baseNameString>
</xtm:baseName>
</xsl:if>
</xsl:for-each>
</xsl:template>
<!-- Varianten werden durch die Traversierung von UML-Generalisierungsrelationen und die Suche nach baseName-Stereotypen gefunden. -->
<xsl:template match="&ELEM;/&CLASS;" mode="getVariants">
<xsl:variable name="xmiId" select="@xmi.id"/>
<xsl:for-each select="../&FC;.Generalization [&SUPERTYPE;/&CLASS;/@xmi.idref = $xmiId]">
<xsl:variable name="subtypeXmiId" select="&FC;.Generalization.subtype/&CLASS;/@xmi.idref"/>
<xsl:variable name="variantClass" select="key('classKey',$subtypeXmiId)"/>
<xsl:if test="$variantClass/&STEREOTYPE;/@xmi.idref = $VARIANT_ID">
<xsl:variable name="name" select="$variantClass/&NAME;"/>
<xtm:variant>
<xtm:variantName>
<xsl:call-template name="resourceRep">
<xsl:with-param name="class" select="$variantClass"/>
</xsl:call-template>
</xtm:variantName>
<xtm:parameters>
<xsl:call-template name="getVariantParams">
<xsl:with-param name="class" select="$variantClass"/>
</xsl:call-template>
</xtm:parameters>
<!-- Wechselt Kontext zu dieser Variante, um zu verschachtelten Varianten zu kommen, falls vorhanden. -->
<xsl:apply-templates select="$variantClass" mode="getVariants"/>
</xtm:variant>
</xsl:if>
</xsl:for-each>
</xsl:template>
<!-- Holt die Parameter einer Variante aus den Attributen der Variantenklasse -->
<xsl:template name="getVariantParams">
<xsl:param name="class"/>
<xsl:if test="not($class/&ATTR;)">
<xsl:message terminate="{$termOnErr}">A variant must have at least one parameter.</xsl:message>
</xsl:if>
<xsl:for-each select="$class/&ATTR;">
<!-- Ein Parameter wird entweder als subjectIndicatorRef oder als topicRef modelliert -->
<xsl:choose>
<xsl:when test="&STEREOTYPE;/@xmi.idref = $SUBJECT_ID">
<xtm:subjectIndicatorRef xlink:href="{&EXPRBODY;}"/>
</xsl:when>
<xsl:otherwise>
<xtm:topicRef xlink:href="{&EXPRBODY;}"/>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:template>Las ocurrencias relacionan clases con datos o referencias. Los datos integrados pueden ser demasiado grandes para un atributo; su descripción sirve de almacenamiento alternativo:
<!-- Topic Map-Belegstellen werden als Assoziationen zu Klassen modelliert, die Ressourcenreferenzen oder -daten enthalten. -->
<xsl:template match="&ELEM;/&CLASS;" mode="getOccurrences">
<xsl:variable name="xmiId" select="@xmi.id"/>
<!-- Suche in den Assoziationen, an denen diese Klasse beteiligt ist -->
<xsl:for-each select="../&ASSOC;[&CONN;/*/&ENDTYPE;/&CLASS;/@xmi.idref = $xmiId]">
<!-- Teste Vorhandensein des Stereotyps occurrence -->
<xsl:if test="&STEREOTYPE;/@xmi.idref = $OCCURRENCE_ID">
<!-- Hole die id der Ressource, indem das andere Ende der occurrence-Assoziation betrachtet wird. -->
<xsl:variable name="resourceId" select="&CONN;/*/&ENDTYPE;/&CLASS;[@xmi.idref != $xmiId]/@xmi.idref"/>
<!-- Hole die Klasse, die die Ressource darstellt -->
<xsl:variable name="resourceClass" select="key('classKey',$resourceId)"/>
<xtm:occurrence>
<xsl:apply-templates select="." mode="getInstanceOf">
<xsl:with-param name="classId" select="$resourceId"/>
</xsl:apply-templates>
<!-- TODO: Das kann noch nicht modelliert werden!
<xsl:call-template name="getScope">
<xsl:with-param name="class"/>
</xsl:call-template>
-->
<!-- Wir können entweder eine Ressourcenreferenz oder Ressourcendaten haben. Falls die Klasse das Attribut resourceData hat, dann ist Letzteres der Fall. -->
<xsl:call-template name="resourceRep">
<xsl:with-param name="class" select="$resourceClass"/>
</xsl:call-template>
</xtm:occurrence>
</xsl:if>
</xsl:for-each>
</xsl:template>
<!-- Dieses Template bestimmt, wie die Ressource dargestellt wird -->
<xsl:template name="resourceRep">
<xsl:param name="class" />
<xsl:variable name="resourceData">
<!-- for-each für einen Kontextwechsel -->
<xsl:for-each select="$class/&ATTR;[&NAME; = 'resourceData']">
<xsl:choose>
<!-- Die Ressourcendaten wurden in der Dokumentation des UML-Attributs kodiert -->
<xsl:when test="&TAGGEDVALUE;">
<xsl:value-of select="&TAGGEDVALUE;"/>
</xsl:when>
<!-- Die Ressourcendaten wurden im UML-Attributwert kodiert -->
<xsl:otherwise>
<xsl:value-of select="&EXPRBODY;"/>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:variable>
<!-- Wenn wir Ressourcendaten haben, benutzen wir sie, sonst nehmen wir an, der Benutzer meinte eine Referenz. -->
<xsl:choose>
<xsl:when test="string($resourceData)">
<xtm:resourceData>
<xsl:value-of select="$resourceData"/>
</xtm:resourceData>
</xsl:when>
<xsl:otherwise>
<xsl:variable name="resource">
<xsl:call-template name="getResourceIdentity">
<xsl:with-param name="class" select="$class"/>
</xsl:call-template>
</xsl:variable>
<xtm:resourceRef xlink:href="{$resource}"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>Las relaciones XTM de tipo instanceOf se modelan como asociaciones de dependencia UML, también llamadas instanciaciones. Esta representación de instanceOf es natural:
<!-- Dieses Template findet heraus, ob eine Topic-Klasse irgendwelche instanceOf-Beziehungen hat. -->
<xsl:template match="&ELEM;/&CLASS;" mode="getInstanceOf">
<xsl:param name="classId"/>
<!-- Wir iterieren über die dependency-Relationen und bestimmen, wie die Instanz dargestellt wird. -->
<xsl:for-each select="&DEPENDENCY;[&CLIENT;/&CLASS;/@xmi.idref = $classId]">
<xtm:instanceOf>
<xsl:variable name="instanceClass" select="key('classKey',&SUPPLIER;/&CLASS;/@xmi.idref)"/>
<!-- Finde heraus, ob die Instanz als Aussagegegenstand oder als Topic modelliert ist. -->
<xsl:variable name="sterotypeId" select="$instanceClass/&STEREOTYPE;/@xmi.idref"/>
<xsl:choose>
<!-- Das gilt bei der Beschreibung eines Aussagegegenstands -->
<xsl:when test="$sterotypeId = $SUBJECT_ID">
<xsl:variable name="subjectIdentity">
<xsl:call-template name="getSubjectIdentity">
<xsl:with-param name="class" select="$instanceClass"/>
</xsl:call-template>
</xsl:variable>
<xsl:if test="not(normalize-space($subjectIdentity))">
<xsl:message terminate="{$termOnErr}">Subject with no identity!</xsl:message>
</xsl:if>
<xtm:subjectIndicatorRef xlink:href="{$subjectIdentity}"/>
</xsl:when>
<!-- Sonst wird die Instanz durch ein Topic dargestellt -->
<xsl:when test="not($sterotypeId) or $sterotypeId = $TOPIC_ID">
<xsl:variable name="topicId">
<xsl:call-template name="getTopicId">
<xsl:with-param name="class" select="$instanceClass"/>
</xsl:call-template>
</xsl:variable>
<xsl:if test="not(normalize-space($topicId))">
<xsl:message terminate="{$termOnErr}">Topic with no id!</xsl:message>
</xsl:if>
<topicRef xlink:href="{$topicId}"/>
</xsl:when>
<xsl:otherwise>
<xsl:message terminate="{$termOnErr}">
<xsl:text>instanceOf must point to a topic or a subject. </xsl:text>
<xsl:value-of select="$instanceClass/&NAME;"/>
<xsl:text> is a </xsl:text>
<xsl:value-of select="key('stereotypeKey',$sterotypeId)/&NAME;"/>
<xsl:text>.
</xsl:text>
</xsl:message>
</xsl:otherwise>
</xsl:choose>
</xtm:instanceOf>
</xsl:for-each>
</xsl:template>
<xsl:template name="getScope">
<xsl:param name="class"/>
<xsl:variable name="classesAssociations" select="/*/XMI.content/*/&ELEM;/&ASSOC;[&CONN;/*/&FC;.AssociationEnd.type/&CLASS;/@xmi.idref = $class/@xmi.id]"/>
<xsl:variable name="scopeAssociations" select="$classesAssociations[&FC;.ModelElement.stereotype/&FX;.Stereotype/@xmi.idref = $SCOPE_ID]"/>
<xsl:if test="$scopeAssociations">
<xtm:scope>
<xsl:for-each select="$scopeAssociations">
<xsl:variable name="targetClassId" select="&CONN;/*/&ENDTYPE;/&CLASS;[@xmi.idref != $class/@xmi.id]/@xmi.idref"/>
<xsl:variable name="targetClass" select="key('classKey',$targetClassId)"/>
<xsl:call-template name="getScopeRef">
<xsl:with-param name="class" select="$targetClass"/>
</xsl:call-template>
</xsl:for-each>
</xtm:scope>
</xsl:if>
</xsl:template>
<xsl:template name="getScopeRef">
<xsl:param name="class"/>
<xsl:variable name="stereotypeId" select="$class/&FC;.ModelElement.stereotype/&FX;.Stereotype/@xmi.idref"/>
<xsl:choose>
<xsl:when test="not($stereotypeId) or $stereotypeId = $TOPIC_ID">
<xsl:variable name="topidId">
<xsl:call-template name="getTopicId">
<xsl:with-param name="class" select="$class"/>
</xsl:call-template>
</xsl:variable>
<xtm:topicRef xlink:href="{$topidId}"/>
</xsl:when>
<xsl:when test="$stereotypeId = $SUBJECT_ID">
<xsl:variable name="subjectId">
<xsl:call-template name="getSubjectIdentity">
<xsl:with-param name="class" select="$class"/>
</xsl:call-template>
</xsl:variable>
<xtm:subjectIndicatorRef xlink:href="{$subjectId}"/>
</xsl:when>
<xsl:when test="$stereotypeId = $RESOURCE_ID">
<xsl:variable name="resourceId">
<xsl:call-template name="getResourceIdentity">
<xsl:with-param name="class" select="$class"/>
</xsl:call-template>
</xsl:variable>
<xtm:resourceRef xlink:href="{$resourceId}"/>
</xsl:when>
<xsl:otherwise>
<xsl:message terminate="{$termOnErr}">A Scope must be either a topicRef, subjectRef, or resourceRef!</xsl:message>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="text( )" mode="topics"/>
<!--= = = = = = = = = = = = = = = = = = = = = = = = =-->
<!-- UML-ASSOZIATION NACH TOPIC-BEZIEHUNGEN -->
<!--= = = = = = = = = = = = = = = = = = = = = = = = =-->
<xsl:template match="&ASSOC;" mode="associations">
<!-- Nur benannte UML-Assoziationen sind Topic Map-Beziehungen -->
<xsl:if test="normalize-space(&NAME;)">
<xtm:association id="{&NAME;}">
<xtm:instanceOf>
<topicRef xlink:href="{key('stereotypeKey',&STEREOTYPE;/@xmi.idref)/&NAME;}"/>
</xtm:instanceOf>
<xsl:for-each select="&CONNEND;">
<xtm:member>
<xtm:roleSpec>
<xtm:topicRef xlink:href="{&NAME;}"/>
</xtm:roleSpec>
<xsl:variable name="topicId">
<xsl:call-template name="getTopicId">
<xsl:with-param name="class" select="key('classKey',&ENDTYPE;/&CLASS;/@xmi.idref)"/>
</xsl:call-template>
</xsl:variable>
<xtm:topicRef xlink:href="{$topicId}"/>
</xtm:member>
</xsl:for-each>
</xtm:association>
</xsl:if>
</xsl:template>
<xsl:template match="&ELEM;/&FC;.Generalization" mode="associations">
<xsl:variable name="subClassId" select="&SUBTYPE;/&CLASS;/@xmi.idref"/>
<xsl:variable name="subClass" select="key('classKey',$subClassId)"/>
<xsl:variable name="superClassId" select="&SUPERTYPE;/&CLASS;/@xmi.idref"/>
<xsl:variable name="superClass" select="key('classKey',$superClassId)"/>
<!-- Wenn es eine Generalisierungsbeziehung zwischen zwei Topics gibt, verwenden wir diese als Hinweis auf eine kanonische Oberklasse-Unterklasse-Beziehung, Idealerweise würden wir das Fehlen eines Stereotyps bei der Generalisierung verwenden, aber meine XMI-Version speichert keine Stereotyp-Angaben über Generalisierungen. -->
<xsl:if test="(not($subClass/&STEREOTYPE;/@xmi.idref) or $subClass/&STEREOTYPE;/@xmi.idref = $TOPIC_ID) and (not($superClass/&STEREOTYPE;/@xmi.idref) or $superClass/&STEREOTYPE;/@xmi.idref = $TOPIC_ID)">
<xtm:association>
<xsl:variable name="id">
<xsl:choose>
<xsl:when test="normalize-space(&NAME;)">
<xsl:value-of select="&NAME;"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="@xmi.id"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:attribute name="id">
<xsl:value-of select="$id"/>
</xsl:attribute>
<xtm:instanceOf>
<subjectIndicatorRef xlink:href="&TM.ORG;#psi-superclass-subclass"/>
</xtm:instanceOf>
<xtm:member>
<xtm:roleSpec>
<xtm:subjectIndicatorRef xlink:href="&TM.ORG;#psi-superclass"/>
</xtm:roleSpec>
<xsl:variable name="superClassTopicId">
<xsl:call-template name="getTopicId">
<xsl:with-param name="class" select="$superClass"/>
</xsl:call-template>
</xsl:variable>
<xtm:topicRef xlink:href="{$superClassTopicId}"/>
</xtm:member>
<xtm:member>
<xtm:roleSpec>
<xtm:subjectIndicatorRef xlink:href="&TM.ORG;#psi-subclass"/>
</xtm:roleSpec>
<xsl:variable name="subClassTopicId">
<xsl:call-template name="getTopicId">
<xsl:with-param name="class" select="$subClass"/>
</xsl:call-template>
</xsl:variable>
<xtm:topicRef xlink:href="{$subClassTopicId}"/>
</xtm:member>
</xtm:association>
</xsl:if>
</xsl:template>
<xsl:template match="text( )" mode="associations"/>
</xsl:stylesheet>Las plantillas de segunda pasada convierten asociaciones restantes. Su estereotipo es el topicRef que determina su tipo. UML no tiene mejor lugar para esta información. Aquí se ignoran asociaciones con ámbito. Por lo demás, UML corresponde bien a las asociaciones de topic maps:
<!--= = = = = = = = = = = = = = = = = = = = = = =-->
<!-- UML-ASSOZIATION NACH TOPIC-BEZIEHUNG -->
<!--= = = = = = = = = = = = = = = = = = = = = = =-->
<xsl:template match="&ASSOC;" mode="associations">
<!-- Nur benannte UML-Assoziationen sind Topic Map-Beziehungen -->
<xsl:if test="normalize-space(&NAME;)">
<xtm:association id="{&NAME;}">
<xtm:instanceOf>
<topicRef xlink:href="{key('stereotypeKey',&STEREOTYPE;/@xmi.idref)/&NAME;}"/>
</xtm:instanceOf>
<xsl:for-each select="&CONNEND;">
<xtm:member>
<xtm:roleSpec>
<xtm:topicRef xlink:href="{&NAME;}"/>
</xtm:roleSpec>
<xsl:variable name="topicId">
<xsl:call-template name="getTopicId">
<xsl:with-param name="class" select="key('classKey',&ENDTYPE;/&CLASS;/@xmi.idref)"/>
</xsl:call-template>
</xsl:variable>
<xtm:topicRef xlink:href="{$topicId}"/>
</xtm:member>
</xsl:for-each>
</xtm:association>
</xsl:if>
</xsl:template>
<xsl:template match="&ELEM;/&FC;.Generalization" mode="associations">
<xsl:variable name="subClassId" select="&SUBTYPE;/&CLASS;/@xmi.idref"/>
<xsl:variable name="subClass" select="key('classKey',$subClassId)"/>
<xsl:variable name="superClassId" select="&SUPERTYPE;/&CLASS;/@xmi.idref"/>
<xsl:variable name="superClass" select="key('classKey',$superClassId)"/>Una generalización entre topics indica una relación canónica superclass-subclass. XTM la admite mediante indicadores de sujeto publicados ( published subject indicators, o PSI). Lo ideal sería usar la ausencia de estereotipo, pero mi versión XMI no los almacena:
<xsl:if test="(not($subClass/&STEREOTYPE;/@xmi.idref) or $subClass/&STEREOTYPE;/@xmi.idref = $TOPIC_ID) and (not($superClass/&STEREOTYPE;/@xmi.idref) or $superClass/&STEREOTYPE;/@xmi.idref = $TOPIC_ID)">
<xtm:association>
<xsl:variable name="id">
<xsl:choose>
<xsl:when test="normalize-space(&NAME;)">
<xsl:value-of select="&NAME;"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="@xmi.id"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:attribute name="id">
<xsl:value-of select="$id"/>
</xsl:attribute>
<xtm:instanceOf>
<subjectIndicatorRef xlink:href="&TM.ORG;#psi-superclass-subclass"/>
</xtm:instanceOf>
<xtm:member>
<xtm:roleSpec>
<xtm:subjectIndicatorRef xlink:href="&TM.ORG;#psi-superclass"/>
</xtm:roleSpec>
<xsl:variable name="superClassTopicId">
<xsl:call-template name="getTopicId">
<xsl:with-param name="class" select="$superClass"/>
</xsl:call-template>
</xsl:variable>
<xtm:topicRef xlink:href="{$superClassTopicId}"/>
</xtm:member>
<xtm:member>
<xtm:roleSpec>
<xtm:subjectIndicatorRef xlink:href="&TM.ORG;#psi-subclass"/>
</xtm:roleSpec>
<xsl:variable name="subClassTopicId">
<xsl:call-template name="getTopicId">
<xsl:with-param name="class" select="$subClass"/>
</xsl:call-template>
</xsl:variable>
<xtm:topicRef xlink:href="{$subClassTopicId}"/>
</xtm:member>
</xtm:association>
</xsl:if>
</xsl:template>
<xsl:template match="text( )" mode="associations"/>
</xsl:stylesheet>Discusión
Las topic maps representan conocimiento del mundo para encontrar información más rápida y precisa. Surgieron en 1993 en un documento del grupo Davenport, fundado por un proveedor Unix con O’Reilly & Associates entre otros, y evolucionaron en GCA Research Institute, hoy IDEAlliance, con aplicaciones de HyTime. XTM resulta de ese trabajo coordinado por la organización independiente TopicMaps.org.
Un topic representa electrónicamente un sujeto real. El músico Ozzy Osborne no puede guardarse en un ordenador; un topic lo representa. Su nombre es una denominación base ( base name). Un nombre universal se llama sin restricciones ( unconstrained ), y puede haber nombres específicos de un ámbito. Un ámbito ( scope) es un contexto donde vale una característica. Para nombres, indica que el topic Ozzy Osborne en el ámbito legal es John Michael Osbourne. Salvo cambio legal a Ozzy, en cuyo caso quizá solo su madre valore ese ámbito.
Un topic puede referenciar una ocurrencia ( occurrence) como recurso relevante. Puede referenciar contenido direccionable (resourceRef) o contener los datos (resourceData).
Una relación especial llamada instanceOf identifica una instancia de una clase general, referenciada por otro topic o indicador. Los indicadores de sujeto ( subject indicators) aclaran sujetos mediante direcciones publicadas estándar, por ejemplo mantenidas por un organismo nacional.
Los topics se conectan por relaciones. Una asociación ( association) nombra una relación entre varios topics, cada uno con un rol.
Hay más funciones para modelar conocimiento. Consulte la especificación XTM, accesible incluso para principiantes, en TopicMaps.org. Casi todas las funciones corresponden a UML como se describió. El ámbito es la dificultad principal. Un ámbito limita una característica a un entorno. Nombres, asociaciones y ocurrencias tienen ámbitos. Nuestras convenciones admiten nombres, no los demás, modelados como asociaciones UML normalmente independientes del contexto. Restricciones UML ( constraints) podrían modelarlo, pero XMI de Rose no las admite. Son funciones avanzadas que muchos usuarios no necesitan; la limitación importa poco a principiantes.
El siguiente diagrama UML modela un tomate en una comida. Sam Hunting usa ese ejemplo peculiar en XML Topic Maps: Creating and Using Topic Maps for the Web (Addison-Wesley, 2002), mostrando funciones para comprobar el XMI resultante.
Figura: Diagrama UML de topic map de tomate.
Sigue parte del archivo XTM resultante:
<xtm:topicMap xmlns:xtm="http://www.topicmaps.org/xtm/1.0" xmlns:xlink="http://www.w3.org/1999/xlink">
<xtm:topic id="EN">
<xtm:subjectIdentity>
<xtm:subjectIndicatorRef xlink:href="http://www.topicmaps.org/xtm/1.0/language.xtm#en"/>
</xtm:subjectIdentity>
<xtm:baseName>
<xtm:baseNameString>EN</xtm:baseNameString>
</xtm:baseName>
</xtm:topic>
<xtm:topic id="FR">
<xtm:subjectIdentity>
<xtm:subjectIndicatorRef xlink:href="http://www.topicmaps.org/xtm/1.0/language.xtm#fr"/>
</xtm:subjectIdentity>
<xtm:baseName>
<xtm:baseNameString>FR</xtm:baseNameString>
</xtm:baseName>
</xtm:topic>
<xtm:topic id="myTomato">
<xtm:subjectIdentity>
<xtm:subjectIndicatorRef xlink:href="http://www.fed.gov/usda/doc/tomato.htm#gradeA"/>
</xtm:subjectIdentity>
<xtm:baseName>
<xtm:baseNameString>tomato</xtm:baseNameString>
</xtm:baseName>
<xtm:baseName>
<xtm:scope>
<xtm:topicRef xlink:href="#EN"/>
</xtm:scope>
<xtm:baseNameString>tomato</xtm:baseNameString>
</xtm:baseName>
<xtm:baseName>
<xtm:scope>
<xtm:topicRef xlink:href="#FR"/>
</xtm:scope>
<xtm:baseNameString>tomato</xtm:baseNameString>
</xtm:baseName>
<xtm:variant>
<xtm:variantName>
<xtm:resourceData>TMT</xtm:resourceData>
</xtm:variantName>
<xtm:parameters>
<xtm:topicRef xlink:href="cell_phone"/>
<xtm:topicRef xlink:href="TMT"/>
</xtm:parameters>
</xtm:variant>
<xtm:occurrence>
<xtm:resourceRef xlink:href="#tomato.gif"/>
</xtm:occurrence>
</xtm:topic>
<xtm:topic id="myConfite">
<xtm:baseName>
<xtm:baseNameString>tomato confite farcie aux douze saveurs</xtm:baseNameString>
</xtm:baseName>
<xtm:instanceOf>
<topicRef xlink:href="#desert"/>
</xtm:instanceOf>
</xtm:topic>
<!-- Ausgelassen -->
<xtm:association id="tomato_confite_association">
<xtm:instanceOf>
<topicRef xlink:href="ingredient_of"/>
</xtm:instanceOf>
<xtm:member>
<xtm:roleSpec>
<xtm:topicRef xlink:href="anIngredient"/>
</xtm:roleSpec>
<xtm:topicRef xlink:href="myTomato"/>
</xtm:member>
<xtm:member>
<xtm:roleSpec>
<xtm:topicRef xlink:href="aDish"/>
</xtm:roleSpec>
<xtm:topicRef xlink:href="myConfite"/>
</xtm:member>
</xtm:association>
<xtm:association id="caramels_confite">
<xtm:instanceOf>
<topicRef xlink:href="ingredient_of"/>
</xtm:instanceOf>
<xtm:member>
<xtm:roleSpec>
<xtm:topicRef xlink:href="anIngredient"/>
</xtm:roleSpec>
<xtm:topicRef xlink:href="myCarmel"/>
</xtm:member>
<xtm:member>
<xtm:roleSpec>
<xtm:topicRef xlink:href="aDish"/>
</xtm:roleSpec>
<xtm:topicRef xlink:href="myConfite"/>
</xtm:member>
</xtm:association>
<!-- Ausgelassen -->
</xtm:topicMap>Véase también
UML y XMI son normas de OMG (Object Management Group). Más información: UML.org y CORBA®, XML And XMI® Resource Page.
TopicMaps.org es el sitio oficial de topic maps y XTM.
La receta Generar sitios desde topic maps XTM muestra cómo generar sitios desde topic maps.
Copyright © 2006 O'Reilly Verlag GmbH & Co. KG
Puede imprimir la versión en línea para uso privado.
Para cualquier otro uso, este capítulo de «XSLT Kochbuch» está sujeto a las mismas condiciones que la edición encuadernada. La obra y todas sus partes están protegidas por derechos de autor. Todos los derechos reservados, incluidos reproducción, traducción, microfilmación, almacenamiento y tratamiento en sistemas electrónicos.
O'Reilly Verlag GmbH & Co. KG, Balthasarstraße 81, 50670 Köln, kommentar(at)oreilly.de