gpt4 book ai didi

xml - XSLT 生成文件夹

转载 作者:数据小太阳 更新时间:2023-10-29 01:54:33 24 4
gpt4 key购买 nike

我正在尝试将 XML 文件解析为更小的 XML 文件并将它们放入文件夹中。文件夹是根据 XML 中的某些元素生成的。

如何在 XSLT 中生成文件夹?我能够使用 xsl:result-document 生成文件,但到目前为止我还没有找到如何生成文件夹的方法。

最佳答案

您不需要专门创建文件夹,只需提供所需的完整路径,如 folder1/doc1.xmlFor example :


<?xml version="1.0" encoding="UTF-8"?>
<tests>
<testrun run="test1">
<test name="foo" pass="true" />
<test name="bar" pass="true" />
<test name="baz" pass="true" />
</testrun>
<testrun run="test2">
<test name="foo" pass="true" />
<test name="bar" pass="false" />
<test name="baz" pass="false" />
</testrun>
<testrun run="test3">
<test name="foo" pass="false" />
<test name="bar" pass="true" />
<test name="baz" pass="false" />
</testrun>
</tests>

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="2.0">

<xsl:output method="text"/>
<xsl:output method="html" indent="yes" name="html"/>

<xsl:template match="/">
<xsl:for-each select="//testrun">
<xsl:variable name="filename"
select="concat('output1/',@run,'.html')" />
<xsl:value-of select="$filename" /> <!-- Creating -->
<xsl:result-document href="{$filename}" format="html">
<html><body>
<xsl:value-of select="@run"/>
</body></html>
</xsl:result-document>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>

关于xml - XSLT 生成文件夹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10101191/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com