Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用XSLT提取多个XML值_Xslt - Fatal编程技术网

使用XSLT提取多个XML值

使用XSLT提取多个XML值,xslt,Xslt,我正在使用XSLT从复杂的XML中提取值 xml: <bean id="timingAdvice" class="org.springframework.aop.interceptor.PerformanceMonitorInterceptor" /> <bean id="XMLhandler" class="com.order.OrderStatusSAXHandler"> </bean> 当这是开始标记时,提供的解决方案不提供所需的输出。有没

我正在使用XSLT从复杂的XML中提取值

xml:

   <bean id="timingAdvice" 

class="org.springframework.aop.interceptor.PerformanceMonitorInterceptor" />

<bean id="XMLhandler" class="com.order.OrderStatusSAXHandler">
</bean>

当这是开始标记时,提供的解决方案不提供所需的输出。有没有一种方法可以忽略
bean
标记中的这些引用

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                              xmlns:bn="http://www.springframework.org/schema/beans">
  <xsl:output method="xml" indent="yes" omit-xml-declaration="yes"/>

  <xsl:template match="@* | node()">
    <xsl:copy>
      <xsl:apply-templates select="@* | node()"/>
    </xsl:copy>
  </xsl:template>

  <xsl:template match="bn:bean/@*">
    <xsl:element name="{name()}" namespace="{namespace-uri(..)}">
      <xsl:value-of select="." />
    </xsl:element>
  </xsl:template>
</xsl:stylesheet>

当对示例输入运行此操作时(当它包装在
元素中时),结果是:

<beans 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" xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/util">
  <bean>
    <id>timingAdvice</id>
    <class>org.springframework.aop.interceptor.PerformanceMonitorInterceptor</class>
  </bean>

  <bean>
    <id>XMLhandler</id>
    <class>com.order.OrderStatusSAXHandler</class>
  </bean>
</beans>

计时建议
org.springframework.aop.interceptor.PerformanceMonitorInterceptor
XMLhandler
com.order.OrderStatusSAXHandler

从属性转换的元素的顺序重要吗,或者它们可以以与属性相同的顺序出现吗

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                              xmlns:bn="http://www.springframework.org/schema/beans">
  <xsl:output method="xml" indent="yes" omit-xml-declaration="yes"/>

  <xsl:template match="@* | node()">
    <xsl:copy>
      <xsl:apply-templates select="@* | node()"/>
    </xsl:copy>
  </xsl:template>

  <xsl:template match="bn:bean/@*">
    <xsl:element name="{name()}" namespace="{namespace-uri(..)}">
      <xsl:value-of select="." />
    </xsl:element>
  </xsl:template>
</xsl:stylesheet>

当对示例输入运行此操作时(当它包装在
元素中时),结果是:

<beans 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" xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/util">
  <bean>
    <id>timingAdvice</id>
    <class>org.springframework.aop.interceptor.PerformanceMonitorInterceptor</class>
  </bean>

  <bean>
    <id>XMLhandler</id>
    <class>com.order.OrderStatusSAXHandler</class>
  </bean>
</beans>

计时建议
org.springframework.aop.interceptor.PerformanceMonitorInterceptor
XMLhandler
com.order.OrderStatusSAXHandler

从属性转换的元素的顺序是否重要,或者它们是否可以与属性以相同的顺序出现?

老实说,它只是属性的标识符,因此意义不大。但是,我已经将它更正为id。老实说,它只是它的一个标识符,所以它没有太大的意义。不过,我已经把它改成了id。是的,这似乎很有效。只要它们放在bean下,顺序就不重要了。我有一些比提供的示例更复杂的xml,我必须编写xslt。我可能得想个办法来解决这个问题。+1,回答得好。顺便说一句,输入中属性的顺序是XSLT无法获得的信息,因此这里的最后一个问题是毫无意义的。@LarsH虽然这在技术上是正确的,但我认为很多XSLT处理程序都按照属性在源文档中出现的顺序来处理属性。我知道至少MSXSL是这样的,我不这么认为,因为规范上说不行。我很好奇你怎么知道MSXSL肯定是这样的;它是否有文档记录,或者您只是在几个实例中观察到它,在这种情况下,它可能会在不同的版本或不同的执行环境中发生变化?无论如何,我不反对被问这个问题;只是想指出,依赖XML属性的顺序与XML信息模型是相反的。在建立一个依赖于订单的流程之前,OP应该意识到这一点。@JLRishe为答案欢呼。我是从spring文件来做这件事的,开始的bean标记有一些对spring框架的引用,我怎么能忽略这些,因为这会导致xslt无法工作。是的,这似乎很管用。只要它们放在bean下,顺序就无关紧要了。我有一些比提供的示例更复杂的xml,我必须编写xslt。我可能得想个办法来解决这个问题。+1,回答得好。顺便说一句,输入中属性的顺序是XSLT无法获得的信息,因此这里的最后一个问题是毫无意义的。@LarsH虽然这在技术上是正确的,但我认为很多XSLT处理程序都按照属性在源文档中出现的顺序来处理属性。我知道至少MSXSL是这样的,我不这么认为,因为规范上说不行。我很好奇你怎么知道MSXSL肯定是这样的;它是否有文档记录,或者您只是在几个实例中观察到它,在这种情况下,它可能会在不同的版本或不同的执行环境中发生变化?无论如何,我不反对被问这个问题;只是想指出,依赖XML属性的顺序与XML信息模型是相反的。在建立一个依赖于订单的流程之前,OP应该意识到这一点。@JLRishe为答案欢呼。我是在spring文件中这样做的,并且开始的bean标记有一些对spring框架的引用,我怎么能忽略这些,因为这会导致xslt无法工作。
<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">
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                              xmlns:bn="http://www.springframework.org/schema/beans">
  <xsl:output method="xml" indent="yes" omit-xml-declaration="yes"/>

  <xsl:template match="@* | node()">
    <xsl:copy>
      <xsl:apply-templates select="@* | node()"/>
    </xsl:copy>
  </xsl:template>

  <xsl:template match="bn:bean/@*">
    <xsl:element name="{name()}" namespace="{namespace-uri(..)}">
      <xsl:value-of select="." />
    </xsl:element>
  </xsl:template>
</xsl:stylesheet>
<beans 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" xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/util">
  <bean>
    <id>timingAdvice</id>
    <class>org.springframework.aop.interceptor.PerformanceMonitorInterceptor</class>
  </bean>

  <bean>
    <id>XMLhandler</id>
    <class>com.order.OrderStatusSAXHandler</class>
  </bean>
</beans>