Search code examples
xmlxsltumlxmi

XMI tags with XSLT loops


I'm finding a problem with the xmi tags ( example : UML:Package) my real problem is that I can't use for-each loop with the select option (select="UML:Package") . Here's the XML input code :

<XMI xmi.version='1.2' xmlns:UML="org.omg.xmi.namespace.UML">
  <UML:Package type="stock" exch="nyse"   symbol="ZCXM" company="zacx corp"
        price="28.875"/>
  <UML:Package type="stock" exch="nasdaq" symbol="ZFFX" company="zaffymat inc"
        price="92.250"/>
  <UML:Package type="stock" exch="nasdaq" symbol="ZYSZ" company="zysmergy inc"
        price="20.313"/>
</XMI>

and here's my xslt code :

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"  xmlns:UML="org.omg.xmi.namespace.UML" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<xsl:output indent="yes" />

	<xsl:template match="/">
		<xmi:XMI>
			<xsl:for-each select="UML:Package">
				<stock>
					<xsl:attribute name="exchange">
            <xsl:value-of select="@exch" />
        </xsl:attribute>
					<name>
						<xsl:value-of select="@company" />
					</name>
					<symbol>
						<xsl:value-of select="@symbol" />
					</symbol>
					<price>
						<xsl:value-of select="@price" />
					</price>
				</stock>
				<hi>
				</hi>
			</xsl:for-each>

		</xmi:XMI>
	</xsl:template>

</xsl:stylesheet>

and this is what I get as a result :

<?xml version="1.0" encoding="UTF-8"?><XMI xmlns:UML="org.omg.xmi.namespace.UML"/>

with no erros on the console :

10:10:19,639 INFO  [main] Main  - javax.xml.transform.TransformerFactory=org.apache.xalan.processor.TransformerFactoryImpl

10:10:19,639 INFO [main] Main - java.endorsed.dirs=D:\PFE.metadata.plugins\org.eclipse.wst.xsl.jaxp.launching\endorsed 10:10:19,639 INFO [main] Main - launchFile: D:\PFE.metadata.plugins\org.eclipse.wst.xsl.jaxp.launching\launch\launch.xml 10:10:19,873 INFO [main] JAXPSAXProcessorInvoker - Transforming... 10:10:19,889 INFO [main] JAXPSAXProcessorInvoker - Done.

any help?


Solution

  • Your reported result is not what I get using your code. Your stylesheet has two major issues:

    1. You are using a prefix xmi: without binding it to a namespace; this generates a parsing error and no result is produced.

    2. From the context of your template - i.e. the / root node - the instruction:

      <xsl:for-each select="UML:Package">
      

      selects nothing. It needs to be:

      <xsl:for-each select="XMI/UML:Package">