在xml文件(如build.xml)中编写内联xslt并将其写入不同的xslt文件有什么区别吗

时间:2015-09-30 11:48:05

标签: xslt-1.0

我写了一个从XSLT ant任务调用时工作正常的xsl。但是当build.xml中嵌入相同的脚本时,它会在执行时出错。

这是我的xsl:

 <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ee="http://java.sun.com/xml/ns/javaee">
<xsl:output method="xml" indent="yes"/>

<xsl:param name="XMLFilePath"/> 
<xsl:param name="updates" select="document($XMLFilePath)" />
<xsl:variable name="updateItemsServlet" select="$updates/ee:web-app/ee:servlet" />
<xsl:variable name="updateItemsServlet-mapping" select="$updates/ee:web-app/ee:servlet-mapping" />

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

<xsl:template match="ee:web-app">
    <xsl:copy>
         <xsl:apply-templates select="@* | node()[not(self::ee:servlet)] | ee:servlet[not(ee:servlet-name = $updateItemsServlet/ee:servlet-name)]" /> 
         <xsl:apply-templates select="$updateItemsServlet" />
     </xsl:copy>
</xsl:template> 


</xsl:stylesheet>

第一个输入文件:

<?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_4.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee/web-app_2_4.xsd" id="ProcessExecutor" version="2.4">
        <display-name>ProcessExecutor</display-name>
        <context-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>WEB-INF/config/beans-stgsuite-enterprise.xml</param-value>
        </context-param>
        <listener>
            <listener-class>org.springframework.web.context.ContextLoaderListener
            </listener-class>
        </listener>
        <servlet>
            <servlet-name>CXFServlet</servlet-name>
            <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
            <load-on-startup>1</load-on-startup>
        </servlet>  
        <servlet-mapping>
            <servlet-name>CXFServlet</servlet-name>
            <url-pattern>/services/*</url-pattern>
        </servlet-mapping>
        <servlet>
            <servlet-name>download</servlet-name>
            <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        </servlet>
        <servlet-mapping>
            <servlet-name>download</servlet-name>
            <url-pattern>/download/*</url-pattern>
        </servlet-mapping>  
        <servlet>
            <servlet-name>dispatch</servlet-name>
            <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
            <load-on-startup>2</load-on-startup>
        </servlet>
        <servlet-mapping>
            <servlet-name>dispatch</servlet-name>
            <url-pattern>/send/*</url-pattern>
        </servlet-mapping>
    </web-app>

第二个输入文件:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_4.xsd"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee/web-app_2_4.xsd"
    id="ProcessExecutor" version="2.4">

    <servlet>
        <description>Omi GetDocument</description>
        <display-name>omiGetDocument</display-name>
        <servlet-name>omiGetDocument</servlet-name>
        <servlet-class>com.majescomastek.stgicd.policy.commons.utility.GetOMIDocumentChain</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>omiGetDocument</servlet-name>
        <url-pattern>/omiGetDocService/*</url-pattern>
    </servlet-mapping>
    <servlet>
        <description>PDF Downloader</description>
        <display-name>pdfDownloader</display-name>
        <servlet-name>pdfDownloader</servlet-name>
        <servlet-class>com.majescomastek.ho.comparativerater.pdf.downloader.QuoteProposalPdfDownloader</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>pdfDownloader</servlet-name>
        <url-pattern>/pdfService/*</url-pattern>
    </servlet-mapping>
</web-app>

嵌入xml意味着..inline xslt。在构建文件中添加了相同的xsl,如下所示。

<target name="MyXSLT">
   <xslt in="web.xml" out="output.xml">
      <param name="XMLFilePath" expression="icd-service-web"/>
        <style>
                <string>
                    <![CDATA[
                        <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ee="http://java.sun.com/xml/ns/javaee">
<xsl:output method="xml" indent="yes"/>
<xsl:param name="XMLFilePath"/> 
<xsl:param name="updates" select="document($XMLFilePath)" />
<xsl:variable name="updateItemsServlet" select="$updates/ee:web-app/ee:servlet" />
<xsl:variable name="updateItemsServlet-mapping" select="$updates/ee:web-app/ee:servlet-mapping" />
<xsl:template match="@* | node()">
    <xsl:copy>
        <xsl:apply-templates select="@* | node()"/>
    </xsl:copy>
</xsl:template>
<xsl:template match="ee:web-app">
    <xsl:copy>
         <xsl:apply-templates select="@* | node()[not(self::ee:servlet)] | ee:servlet[not(ee:servlet-name = $updateItemsServlet/ee:servlet-name)]" /> 
         <xsl:apply-templates select="$updateItemsServlet" />
     </xsl:copy>
</xsl:template> 
</xsl:stylesheet>
                    ]]>
                </string>
        </style>
    </xslt>
</target>

0 个答案:

没有答案