0

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?

4

1 回答 1

0

您报告的结果不是我使用您的代码得到的结果。您的样式表有两个主要问题:

  1. 您正在使用前缀xmi:而不将其绑定到命名空间;这会产生解析错误,并且不会产生任何结果。

  2. 从您的模板的上下文 - 即/根节点 - 指令:

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

    什么都不选择。它需要是:

    <xsl:for-each select="XMI/UML:Package">
    
于 2015-04-17T09:46:45.247 回答