Pregunta

I'm trying to print this XML file in an HTML table using out of XSLT and I don't know how to get the information from the XMI and UML tags, like XMI.header or XMI.exporter.

I know how to get the attributes from the root tag XMI but not the other tags under.

XML document

<XMI xmi.version="1.2"
    xmlns:UML="org.omg.xmi.namespace.UML"
    timestamp="Wed Apr 21 18:15:34 CEST 2010">

  <XMI.header>
    <XMI.documentation>
      <XMI.exporter>
        ArgoUML (using Netbeans XMI Writer version 1.0)
      </XMI.exporter>
      <XMI.exporterVersion>0.30(6) revised on $Date: 2010-01-11 22:20:14 +0100 (Mon, 11 Jan 2010) $
      </XMI.exporterVersion>
    </XMI.documentation>
    <XMI.metamodel xmi.name="UML" xmi.version="1.4"/>
  </XMI.header>

  <XMI.content>
    <UML:Multiplicity xmi.id="-64--88-0--57--53f31703:128211b208a:-8000:0000000000000DDF">
      <UML:Multiplicity.range>
    <UML:MultiplicityRange xmi.id="-64--88-0--57--53f31703:128211b208a:-8000:0000000000000DE0"
      lower="1" upper="1"/>
      </UML:Multiplicity.range>
  </XMI.content>

</XMI>

</UML:Multiplicity>

XSLT code

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

<xsl:template match="/">
    <xsl:apply-templates/>
</xsl:template>

<xsl:template match="XMI">
    XMI Version: <xsl:value-of select="./@xmi.version"/>
    <br/>
    Generated: <xsl:value-of select="./@timestamp"/>
    <br/>
</xsl:template>

</xsl:stylesheet>
¿Fue útil?

Solución

XMI.header and XMI.exporter are just ordinary XML tag names. Within the ASCII range the initial character has to be alphanumeric or an underscore, but after that the name can include full-stops and hyphens. So just

<xsl:template match="XMI.header">

will work for you.

The UML names are slightly different becuase UML is a namespace and must be declared at the top of your XSLT stylesheet. So you need

<xsl:stylesheet version="1.0"
    xmlns:UML="org.omg.xmi.namespace.UML"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

after which you can just use the name as it stands, like

<xsl:template match="UML:Multiplicity">
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top