【发布时间】:2013-05-16 12:49:33
【问题描述】:
我正在开发一些 XSLT 以从复杂的 XML 中提取值。
xml:
<bean id="timingAdvice"
class="org.springframework.aop.interceptor.PerformanceMonitorInterceptor" />
<bean id="XMLhandler" class="com.order.OrderStatusSAXHandler">
</bean>
我希望达到的输出:
<bean>
<id>timingAdvice</id>
<class>org.springframework.aop.interceptor.PerformanceMonitorInterceptor</class>
</bean>
<bean>
<id>XMLhandler</id>
<class>com.citi.get.rio.order.OrderStatusSAXHandler</class>
</bean>
我正在使用这个 XSLT:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8"
indent="yes" />
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()" />
</xsl:copy>
</xsl:template>
<xsl:template match="beans/bean">
<xsl:element name="{@class}">
<xsl:apply-templates />
</xsl:element>
</xsl:template>
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()" />
</xsl:copy>
</xsl:template>
<xsl:template match="beans/bean">
<xsl:element name="{@id}">
<xsl:apply-templates />
</xsl:element>
</xsl:template>
</xsl:stylesheet>
但是这个输出:
<?xml version="1.0" encoding="UTF-8"?>
<beans>
<timingAdvice/>
<XMLhandler>
</XMLhandler>
</beans>
这不是我想要的。
我想检查 xml 打印它们的每个属性,如下所示:
<attributeName>value<attributeName>
编辑
我遇到了beans 标记的问题,它包含许多对 Spring 框架的弹簧引用:
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.5.xsd"
default-lazy-init="false">
当这是开始标记时,提供的解决方案不提供所需的输出。有没有办法在beans 标签中忽略这些引用
【问题讨论】:
-
说实话只是它的一个标识符,所以意义不大。但是,我已将其更正为 id。
标签: xslt