【问题标题】:Append context of one XML to another with XSL使用 XSL 将一个 XML 的上下文附加到另一个 XML
【发布时间】:2012-12-24 21:36:01
【问题描述】:

我有问题。我想将两个 XML 文件的上下文合二为一。这在 MAVEN 项目 (POM) 和 XSL 中的 xslt-generator-maven-plugin 的帮助下。

我的 pom 配置如下:

<plugin>
<groupId>net.sf.xsltmp</groupId>
<artifactId>xslt-generator-maven-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>transform-contex</id>
<goals>
<goal>many-to-one</goal>
</goals>
<configuration>
<srcDir>src/main/webapp/META-INF/</srcDir>
<srcIncludes>**/*context.xml</srcIncludes>
<xslTemplate>src/main/webapp/Temp.xsl</xslTemplate>
<destFile>${project.build.directory}/contextNEW.xml</destFile>
</configuration>
</execution>
</executions>
</plugin>

我有第一个文件,例如:

<?xml version="1.0" encoding="UTF-8"?>
<Context debug="0" reloadable="true" >
    <Resourcen name="jdbc/ChiDS"
               auth="Container" 
               type="javax.sql.DataSource"
               ...
</Context>

第二个喜欢:

<?xml version="1.0" encoding="UTF-8"?>
 <Context>
    <Realm className="org.apache.catalina.realm.MemoryRealm"
           pathname="webapps/${application.name}/WEB-INF/users.xml"/>
 </Context>

并且想得到:

<?xml version="1.0" encoding="UTF-8"?>
<Context debug="0" reloadable="true" >  
<Resourcen name="jdbc/ChiDS"
               auth="Container" 
               type="javax.sql.DataSource"
               ...
<Realm className="org.apache.catalina.realm.MemoryRealm"
       pathname="webapps/${application.name}/WEB-INF/users.xml"/> 
</Context>

所以我会将第二个 XML 附加到第一个。我需要创建一个正确的 TEMP.xsl 文件。

我“需要”使用以下内容:

  • xslt-generator-maven-plugin

我试过了,但标记化是个问题。

<xsl:output method="xml" indent="yes"/>

<xsl:param name="source-file-names" />
<xsl:variable name="names-sequence" select="tokenize($source-file-names,'\|')" />
<xsl:variable name="cfg-files" select="document($names-sequence)" />

有什么线索吗?我尝试了几件事,但没有解决这个问题。

感谢您的帮助。

我已尝试使用此 XSL(我修复了令牌问题)但没有成功:

<xsl:output method="xml" indent="yes"/>

<xsl:param name="source-file-names" />
<xsl:variable name="names-sequence" select="fn:tokenize($source-file-names,'\|')" />
<xsl:variable name="cfg-files" select="document($names-sequence)" />

<xsl:template match="/">
    <xsl:copy>
        <xsl:apply-templates select="$cfg-files/*"/>
    </xsl:copy>
</xsl:template>

我看过这个样本:https://github.com/ivos/xslt-generator-maven-plugin/issues/1 但我这边没有成功。

欢迎任何帮助。 :)

【问题讨论】:

    标签: xml xslt maven pom.xml


    【解决方案1】:

    您需要创建第三个 xml 文档,其中包含您要加入的其他 xml 文件。
    我认为这很有帮助:http://www.ibm.com/developerworks/library/x-tipcombxslt/

    【讨论】:

    • 是的,但我不知道有多少文件以及上下文是什么。我可以这样: #1 文件位于 ${project.build.directory}/classes/rebel.xml #2 文件位于 ${project.build.directory}/gis-ol/WEB-INF/classes/rebel .xml #3 文件位于 ${project.build.directory}/war/work/pt.xlm.gir/datageo/WEB-INF/classes/rebel.xml 所以名称也相同。
    • 我不确定 xsl 转换是否可以那么高级/复杂。
    【解决方案2】:

    您可以在此处查看我的示例,其中我使用 xslt 可变文档加载组合了两个 xml 文件。你可以在这里找到它:Transform XML with multiple XSL files

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-06-14
      相关资源
      最近更新 更多