无法在springsource IDE中使用xsl拆分xml文件

无法在springsource IDE中使用xsl拆分xml文件,xml,xslt,Xml,Xslt,我对xsl技术非常陌生。我正在尝试拆分以下文件: <?xml version="1.0" encoding="UTF-8"?> <CustomObject xmlns="http://soap.sforce.com/2006/04/metadata"> <fields> <fullName>StageName</fullName> <picklist> <

我对xsl技术非常陌生。我正在尝试拆分以下文件:

<?xml version="1.0" encoding="UTF-8"?>
<CustomObject xmlns="http://soap.sforce.com/2006/04/metadata">
    <fields>
        <fullName>StageName</fullName>
        <picklist>
            <picklistValues>
                <fullName>Prospecting/Needs/Qualification</fullName>
                <closed>false</closed>
                <default>false</default>
                <forecastCategory>Pipeline</forecastCategory>
                <probability>25</probability>
                <won>false</won>
            </picklistValues>
            <picklistValues>
                <fullName>Proposal/Price Quote</fullName>
                <closed>false</closed>
                <default>false</default>
                <forecastCategory>Pipeline</forecastCategory>
                <probability>40</probability>
                <won>false</won>
            <sorted>false</sorted>
        </picklist>
        <trackFeedHistory>true</trackFeedHistory>
        <trackTrending>false</trackTrending>
        <type>Picklist</type>
    </fields>
    <fields>
        <fullName>Status__c</fullName>
        <externalId>false</externalId>
        <label>Status</label>
        <required>false</required>
        <trackHistory>false</trackHistory>
        <trackTrending>false</trackTrending>
        <type>Text</type>
        <unique>false</unique>
    </fields>
</CustomObject>

舞台剧
勘探/需求/资格
假的
假的
管道
25
假的
建议书/报价
假的
假的
管道
40
假的
假的
真的
假的
挑选名单
状态
假的
地位
假的
假的
假的
正文
假的
两个不同的文件,分别以后者的field/fullname元素命名。所以本质上我想要第一个文件:“StageName.xml”:


舞台剧
勘探/需求/资格
假的
假的
管道
25
假的
建议书/报价
假的
假的
管道
40
假的
假的
真的
假的
挑选名单
第二个文件:“Status__c.xml”:


状态
假的
地位
假的
假的
假的
正文
假的
我根据stackoverflow中的问题和答案编写了以下小脚本:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" 
                xmlns:redirect="http://xml.apache.org/xalan/redirect" 
                extension-element-prefixes="redirect">

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

    <xsl:template match="/root">
        <xsl:apply-templates/>
        <xsl:for-each select="fields">
            <redirect:write file="file_{@id}-output.xml">
                    <xsl:copy-of select="fields"/>
            </redirect:write>
        </xsl:for-each>
    </xsl:template>


</xsl:stylesheet>

我得到的是以下唯一的文件:“Opportunity.out.xml”:


舞台剧
勘探/需求/资格
假的
假的
管道
25
假的
建议书/报价
假的
假的
管道
40
假的
假的
真的
假的
挑选名单
状态
假的
地位
假的
假的
假的
正文
假的
我在SpringSource中通过右键单击-->以-->xsl转换运行split.xsl文件

我为这个问题的巨大规模事先感到抱歉,但我真的不知道从哪里开始解决这个问题


提前感谢。

您需要考虑输入XML中的名称空间,方法是在样式表中声明名称空间的前缀,然后使用该前缀限定元素名称。另外,您发布的示例的根不是
root
,而是
CustomObject
,所以我们需要所有这些

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" 
                xmlns:redirect="http://xml.apache.org/xalan/redirect" 
                xmlns:df="http://soap.sforce.com/2006/04/metadata"
                extension-element-prefixes="redirect"
                exclude-result-prefixes="df redirect">

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

<xsl:template match="/df:CustomObject"> 
  <xsl:apply-templates/>
  <xsl:for-each select="df:fields">
    <redirect:write file="file_{df:fullName}-output.xml">
      <xsl:copy-of select="."/>
    </redirect:write>
  </xsl:for-each>
</xsl:template>

</xsl:stylesheet>

当我从命令行运行Xalan 2.7 Java时,它会生成输出文件
file\u StageName-output.xml
file\u Status\u c-output.xml


所以你可能更想要
。至于如何使其与IDE一起工作,请使用与IDE相关的标签标记您的问题,希望熟悉IDE的人能够提供帮助。

你好,Martin,谢谢您的回答。我尝试了这个解决方案,但仍然得到了我发布的初始输出。您认为这可能与springsource配置有关吗?@Antigoni,我已经编辑了答案并更正了匹配模式,以便与您提供的示例一起使用(也需要更正以使其格式正确)。好的@Martin,再次非常感谢。最后两个快速问题:如何检查我的Xalan版本,以及2。您在命令行中键入什么命令以从那里运行它?再次感谢您的帮助。我按照上的说明进行操作,确保在类路径上有所有四个.jar。另外还有不区分大小写的
-V(Version info)
选项来了解该版本。您好@Martin,再次感谢您的指导。我遵循了所有这些方法,从命令行成功地运行了命令,但仍然得到了一个没有xml标记的输出,并且没有写入两个文件,只是显示在命令行上。我想现在要看xsl文件了,对吧?
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" 
                xmlns:redirect="http://xml.apache.org/xalan/redirect" 
                extension-element-prefixes="redirect">

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

    <xsl:template match="/root">
        <xsl:apply-templates/>
        <xsl:for-each select="fields">
            <redirect:write file="file_{@id}-output.xml">
                    <xsl:copy-of select="fields"/>
            </redirect:write>
        </xsl:for-each>
    </xsl:template>


</xsl:stylesheet>
<?xml version="1.0" encoding="UTF-8"?>


        StageName


                Prospecting/Needs/Qualification
                false
                false
                Pipeline
                25
                false


                Proposal/Price Quote
                false
                false
                Pipeline
                40
                false

            false

        true
        false
        Picklist


        Status__c
        false
        Status
        false
        false
        false
        Text
        false
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" 
                xmlns:redirect="http://xml.apache.org/xalan/redirect" 
                xmlns:df="http://soap.sforce.com/2006/04/metadata"
                extension-element-prefixes="redirect"
                exclude-result-prefixes="df redirect">

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

<xsl:template match="/df:CustomObject"> 
  <xsl:apply-templates/>
  <xsl:for-each select="df:fields">
    <redirect:write file="file_{df:fullName}-output.xml">
      <xsl:copy-of select="."/>
    </redirect:write>
  </xsl:for-each>
</xsl:template>

</xsl:stylesheet>