我希望您的帮助可以使用XSLT将某些XML转换为新的XML文件。我有选择多个XML并在其上应用XSLT的代码。如何将多个xml文件转换并合并为一个文件
我的问题是在XSLT中,我想将shop1.xml shop2xml ..转换为allshops.xml。对于知道如何使用XSLT的人来说,这是一件容易的事,因为只有2-3个变化。
下面您可以找到更好理解的结构。非常感谢你。
shop1.xml
<shop>
<products>
<product id="189">
<title></title>
<description></description>
<price></price>
<image></image>
<url></url>
<category id="61"></category>
</product>
</products>
</shop>
shop2.xml
<shop>
<products>
<product id="182">
<title></title>
<description></description>
<price></price>
<image></image>
<url></url>
<category id="62"></category>
</product>
</products>
</shop>
shop3.xml //这其中有直接的产品为根,ID可能是已经存在
<products>
<product>
<id>123</id>
<title></title>
<description></description>
<price></price>
<image></image>
<url></url>
<category id="62"></category>
</product>
</products>
paths.xml它从PHP代码用于获取多个XML文件
<?xml version="1.0" encoding="utf-8"?>
<files>
<file>shop1.xml</file>
<file>shop2.xml</file>
<file>shop3.xml</file>
</files>
allshops.xml
<products> //removed the store,shop and products stays as root
<product>
<id>the product's attribute id</id> //new element, with value the product id=""
<title></title>
<description></description>
<price></price>
<image></image>
<url></url>
<category></category> //removed the attribute id
<shopid></shopid> //new element, will be blank for now
</product>
<product>
</product>
.
.
.
</products>
这将是更好使用'文档加载的所有文件( )'XSLT 1.0函数。通过这种方式,您将能够正确地将内容包含在一个'products'root中,并且可以用当前文件名填充'shopid'。 –
你好。如果您需要回复,我对此解决方案非常感兴趣。 – EnexoOnoma
看到我的答案。我保留了一般变换,以便包含最终不包含在输入样本中的其他节点。希望能帮助到你。 –