我需要 XSL 文件的输出(输出是 XML 文件),该文件将 XML 文件作为文件夹结构中的输入



我有一个XML文件作为输入,还有一个XSL文件将输入XML文件转换为另一个XML文件。 我需要将该输出XML文件放在特定文件夹中并具有特定名称。 我该怎么做?我尝试使用结果文档,但没有运气,文件名只是显示在输出文件中。

这是我的XML代码(试用版.xml(:

<?xml version="1.0" encoding="utf-8" ?>
<?xml-stylesheet type="text/xsl" href="trail_xslt.xsl"?> 
<!DOCTYPE xml>
<Settings>
<Setting Id="66" Revision="2" Type="e-mail settings"
Name="E-mail setting" Default_Item="false">
<SettingAttributes>
<SettingAttribute Name="email push" Value="Yes" />
<SettingAttribute Name="cost warning" Value="No" />
<SettingAttribute Name="email account name style"
Value="NONE" />
<SettingAttribute
Name="linkedin integration in e-mail" Value="No" />
<SettingAttribute
Name="show truncation limit in bytes" Value="Yes" />
</SettingAttributes>
</Setting>
</Settings>

这是我的XSL代码(Trial.xsl(:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" encoding="UTF-8"  indent="yes" omit-xml-declaration="no" />
<!-- Our goal is to come up with output XML in a folder structure -->
<xsl:template match="/">
<resources>
<integer name="email_account_name_style">
<xsl:choose>
<xsl:when
test="Settings/Setting[@Type = 'e-mail settings']/SettingAttributes/SettingAttribute[@Name = 'email account name style']/@Value = 'NONE'">
0
</xsl:when>
<xsl:when
test="Settings/Setting[@Type = 'e-mail settings']/SettingAttributes/SettingAttribute[@Name = 'email account name style']/@Value = 'EMAIL'">
1
</xsl:when>
<xsl:when
test="Settings/Setting[@Type = 'e-mail settings']/SettingAttributes/SettingAttribute[@Name = 'email account name style']/@Value = 'DOMAIN'">
2
</xsl:when>
</xsl:choose>
</integer>
<integer name="push_email">
<xsl:choose>
<xsl:when
test="Settings/Setting[@Type = 'e-mail settings']/SettingAttributes/SettingAttribute[@Name = 'email push']/@Value = 'Yes'">
1
</xsl:when>
<xsl:when
test="Settings/Setting[@Type = 'e-mail settings']/SettingAttributes/SettingAttribute[@Name = 'email push']/@Value = 'No'">
0
</xsl:when>
</xsl:choose>
</integer>
<bool name="enable_cost_warning">
<xsl:choose>
<xsl:when
test="Settings/Setting[@Type = 'e-mail settings']/SettingAttributes/SettingAttribute[@Name = 'cost warning']/@Value = 'Yes' ">
true
</xsl:when>
<xsl:when
test="Settings/Setting[@Type = 'e-mail settings']/SettingAttributes/SettingAttribute[@Name = 'cost warning']/@Value = 'No' ">
false
</xsl:when>
</xsl:choose>
</bool>
<bool name="enable_linked_in_connection">
<xsl:choose>
<xsl:when
test="Settings/Setting[@Type = 'e-mail settings']/SettingAttributes/SettingAttribute[@Name = 'linkedin integration in e-mail']/@Value = 'Yes'">
true
</xsl:when>
<xsl:when
test="Settings/Setting[@Type = 'e-mail settings']/SettingAttributes/SettingAttribute[@Name = 'linkedin integration in e-mail']/@Value = 'No'">
false
</xsl:when>
</xsl:choose>
</bool>
<bool name="truncation_size_in_bytes">
<xsl:choose>
<xsl:when
test="Settings/Setting[@Type = 'e-mail settings']/SettingAttributes/SettingAttribute[@Name = 'show truncation limit in bytes']/@Value = 'Yes'">
true
</xsl:when>
<xsl:when
test="Settings/Setting[@Type = 'e-mail settings']/SettingAttributes/SettingAttribute[@Name = 'show truncation limit in bytes']/@Value = 'No'">
false
</xsl:when>
</xsl:choose>
</bool>
</resources>
</xsl:template>
</xsl:stylesheet>

我的输出XML文件是这样的(Trial.out.xml(:

<?xml version="1.0" encoding="utf-8"?>
<resources>
<integer name="email_account_name_style">0</integer>
<integer name="push_email">1</integer>
<bool name="enable_cost_warning">false</bool>
<bool name="enable_linked_in_connection">false</bool>
<bool name="truncation_size_in_bytes">true</bool>
</resources>

上面的输出被生成为Trial.out.xml 但是我需要此输出作为 con.xml在以下文件夹结构 E:\sour\resource\values

我尝试在 XSL 中使用以下代码块,但它没有产生任何结果:

<xsl:variable name="filename"
select="concat('E:sourresourcevalues','con','.xml')" />
<xsl:value-of select="$filename" />  <!-- Creating  -->
<xsl:result-document href="E:sourresourcevalues" format="xml">

请帮助我

问候 拉哈里·

我不熟悉 Eclipse 以及它如何使用 Saxon 输出 XSLT 转换的结果,以及它是否有任何配置选项来简单地设置主结果的文件夹和文件名,所以我不能建议任何特定于您的特定工具配置的方法。另请注意,撒克逊 8.9 已有 10 多年的历史,当前版本为 9.8。

但是,在 XSLT 2.0 中,您当然可以直接在xsl:template match="/"中使用xsl:result-document

例如
<xsl:template match="/">
<xsl:result-document href="file:///E:/sour/resources/values/con.xml">
<!-- now output results you want here with literal result elements and/or by using templates e.g. -->
<resources>
...
</resources>
</xsl:result-document>
</xsl:template>

以确保将主要结果写入特定位置。如果需要或需要,您当然可以使用参数或变量以获得更大的灵活性,例如

<xsl:param name="file-name" select="'con.xml'"/>
<xsl:param name="folder-url" select="'file:///E:/sour/resources/values/'"/>

在顶层,然后您可以使用<xsl:result-document href="{$folder-url}{$file-name}">而不是<xsl:result-document href="file:///E:/sour/resources/values/con.xml">

最新更新