Xslt 处理document()func以从2个XML源文件转换为1个目标文件
我有两个xml文档:一个作为源文件,另一个作为字典文件。因为我需要重新构造源文件,还需要为第一个源文件中的每个元素合并额外的信息。我是XSL转换方面的新手,这就是为什么这对我来说是一项艰巨的任务。我想有人能帮我解决这个问题。 -首先,我不知道如何处理字典文件中的$ID。 -第二,我不知道如何处理转换中的层次结构。 第一个文件(源文件1)Xslt 处理document()func以从2个XML源文件转换为1个目标文件,xslt,Xslt,我有两个xml文档:一个作为源文件,另一个作为字典文件。因为我需要重新构造源文件,还需要为第一个源文件中的每个元素合并额外的信息。我是XSL转换方面的新手,这就是为什么这对我来说是一项艰巨的任务。我想有人能帮我解决这个问题。 -首先,我不知道如何处理字典文件中的$ID。 -第二,我不知道如何处理转换中的层次结构。 第一个文件(源文件1) 3332 3333 3331 3335 3336 3334 3337 定义主元素更多细节的字典文件(源文件2) 默认硬盘 默认文件夹 CORELDRAW
3332
3333
3331
3335
3336
3334
3337
定义主元素更多细节的字典文件(源文件2)
默认硬盘
默认文件夹
CORELDRAW文件
PHOTOSHOP文件
MP3文件
MP4文件
WMV文件
访问文件
EXCEL文件
目标文件将成为以下文件:
<?xml version="1.0" encoding="UTF-8"?>
<def id="MANAGE_STORAGE" transform="scale(1)">
<def id="HARDDISKS" class="HARDDISKS">
<def id="111A" class="HARDDISK" drag= "editAttributeDblClk(evt,'$ID');MouseDown(evt);">
<def transform=" size(200 200)"/>
<def transform="size(-25,100)" textgroup="yes">
<text x="0" y="0" style="ABC" transform="rotate(270)">
<tspan>DEFAULT HARDDISK</tspan>
</text>
</def>
<def id="FOLDERS_111A" class ="FOLDERS">
<def id="222A" class="FOLDER" drag= "editAttributeDblClk(evt,'$ID');MouseDown(evt);">
<def transform=" size100 100)"/>
<def transform="size(-25,100)" textgroup="yes">
<text x="0" y="0" style="BCD" transform="rotate(270)">
<tspan> FOLDER 1</tspan>
</text>
</def>
<def id="GRAPHICS_222A" class ="GRAPHICS">
<def id ='3332' class="CORELDRAW">
<def transform=" size(90 70)"/>
<def transform="size(-25,100)" textgroup="yes">
<text x="0" y="0" style="BCD" transform="rotate(270)">
<tspan>model1</tspan>
</text>
</def>
</def>
</def>
<def id="OFFICES_222A" class ="OFFICES"/>
<def id="MUSICS_222A" class ="MUSICS">
<def id ='3333' class="MP3">
<def transform=" size(70 70)"/>
<def transform="size(-25,100)" textgroup="yes">
<text x="0" y="0" style="BWCD" transform="rotate(270)">
<tspan>hello song</tspan>
</text>
</def>
</def>
</def>
<def id="VIDEOS_222A" class ="VIDEOS"/>
</def>
<def id="222B" class="FOLDER" drag= "editAttributeDblClk(evt,'$ID');MouseDown(evt);">
<def transform=" size100 100)"/>
<def transform="size(-25,100)" textgroup="yes">
<text x="0" y="0" style="BCD" transform="rotate(270)">
<tspan> FOLDER 2</tspan>
</text>
</def>
<def id="GRAPHICS_222B" class ="GRAPHICS">
<def id ='3331' class="PHOTOSHOP">
<def transform=" size(90 70)"/>
<def transform="size(-25,100)" textgroup="yes">
<text x="0" y="0" style="BCWD" transform="rotate(270)">
<tspan>model2</tspan>
</text>
</def>
</def>
</def>
<def id="OFFICES_222B" class ="OFFICES">
<def id ='3335' class="ACCESS">
<def transform=" size100 50)"/>
<def transform="size(-25,100)" textgroup="yes">
<text x="0" y="0" style="BCD" transform="rotate(270)">
<tspan>program1</tspan>
</text>
</def>
</def>
<def id ='3336' class="EXCEL">
<def transform=" size100 50)"/>
<def transform="size(-25,100)" textgroup="yes">
<text x="0" y="0" style="BCD" transform="rotate(270)">
<tspan>schedule</tspan>
</text>
</def>
</def>
</def>
<def id="MUSICS_222B" class ="MUSICS"/>
<def id="VIDEOS_222B" class ="VIDEOS">
<def id ='3337' class="MP4">
<def transform=" size(80 90)"/>
<def transform="size(-25,100)" textgroup="yes">
<text x="0" y="0" style="WBCD" transform="rotate(270)">
<tspan>pop music</tspan>
</text>
</def>
</def>
<def id ='3334' class="WMV">
<def transform=" size(80 90)"/>
<def transform="size(-25,100)" textgroup="yes">
<text x="0" y="0" style="BCD" transform="rotate(270)">
<tspan>rock rock music</tspan>
</text>
</def>
</def>
</def>
</def>
</def>
<def id="SHOTCUTS_111A" class ="SHOTCUTS"/>
</def>
</def>
</def>
默认硬盘
文件夹1
模型1
你好歌
文件夹2
模型2
方案1
日程
流行音乐
摇滚乐
所以我知道我必须处理document()函数,该函数在转换文件中声明为变量。
但我需要知道如何将两个XML源文件合并并重新构造为一个XML目标文件。
有人帮我吗?欢迎大家帮忙。
或者你能给我看看解决这个问题的方法吗?
或者你可以帮我确定这个转换的算法。
非常感谢
<xsl:value-of select="document('definitions.xml')/definitions/def[@id = 'someID']"/>
当然,您应该将
document('foo.xml')
结果放在顶级变量中。对不起,我没有注意到您正在寻找合并算法。
<?xml version="1.0" encoding="UTF-8"?>
<def id="MANAGE_STORAGE" transform="scale(1)">
<def id="HARDDISKS" class="HARDDISKS">
<def id="111A" class="HARDDISK" drag= "editAttributeDblClk(evt,'$ID');MouseDown(evt);">
<def transform=" size(200 200)"/>
<def transform="size(-25,100)" textgroup="yes">
<text x="0" y="0" style="ABC" transform="rotate(270)">
<tspan>DEFAULT HARDDISK</tspan>
</text>
</def>
<def id="FOLDERS_111A" class ="FOLDERS">
<def id="222A" class="FOLDER" drag= "editAttributeDblClk(evt,'$ID');MouseDown(evt);">
<def transform=" size100 100)"/>
<def transform="size(-25,100)" textgroup="yes">
<text x="0" y="0" style="BCD" transform="rotate(270)">
<tspan> FOLDER 1</tspan>
</text>
</def>
<def id="GRAPHICS_222A" class ="GRAPHICS">
<def id ='3332' class="CORELDRAW">
<def transform=" size(90 70)"/>
<def transform="size(-25,100)" textgroup="yes">
<text x="0" y="0" style="BCD" transform="rotate(270)">
<tspan>model1</tspan>
</text>
</def>
</def>
</def>
<def id="OFFICES_222A" class ="OFFICES"/>
<def id="MUSICS_222A" class ="MUSICS">
<def id ='3333' class="MP3">
<def transform=" size(70 70)"/>
<def transform="size(-25,100)" textgroup="yes">
<text x="0" y="0" style="BWCD" transform="rotate(270)">
<tspan>hello song</tspan>
</text>
</def>
</def>
</def>
<def id="VIDEOS_222A" class ="VIDEOS"/>
</def>
<def id="222B" class="FOLDER" drag= "editAttributeDblClk(evt,'$ID');MouseDown(evt);">
<def transform=" size100 100)"/>
<def transform="size(-25,100)" textgroup="yes">
<text x="0" y="0" style="BCD" transform="rotate(270)">
<tspan> FOLDER 2</tspan>
</text>
</def>
<def id="GRAPHICS_222B" class ="GRAPHICS">
<def id ='3331' class="PHOTOSHOP">
<def transform=" size(90 70)"/>
<def transform="size(-25,100)" textgroup="yes">
<text x="0" y="0" style="BCWD" transform="rotate(270)">
<tspan>model2</tspan>
</text>
</def>
</def>
</def>
<def id="OFFICES_222B" class ="OFFICES">
<def id ='3335' class="ACCESS">
<def transform=" size100 50)"/>
<def transform="size(-25,100)" textgroup="yes">
<text x="0" y="0" style="BCD" transform="rotate(270)">
<tspan>program1</tspan>
</text>
</def>
</def>
<def id ='3336' class="EXCEL">
<def transform=" size100 50)"/>
<def transform="size(-25,100)" textgroup="yes">
<text x="0" y="0" style="BCD" transform="rotate(270)">
<tspan>schedule</tspan>
</text>
</def>
</def>
</def>
<def id="MUSICS_222B" class ="MUSICS"/>
<def id="VIDEOS_222B" class ="VIDEOS">
<def id ='3337' class="MP4">
<def transform=" size(80 90)"/>
<def transform="size(-25,100)" textgroup="yes">
<text x="0" y="0" style="WBCD" transform="rotate(270)">
<tspan>pop music</tspan>
</text>
</def>
</def>
<def id ='3334' class="WMV">
<def transform=" size(80 90)"/>
<def transform="size(-25,100)" textgroup="yes">
<text x="0" y="0" style="BCD" transform="rotate(270)">
<tspan>rock rock music</tspan>
</text>
</def>
</def>
</def>
</def>
</def>
<def id="SHOTCUTS_111A" class ="SHOTCUTS"/>
</def>
</def>
</def>
<xsl:value-of select="document('definitions.xml')/definitions/def[@id = 'someID']"/>