我找到了多個關于xsl:for-each的教程、文章和帖子等,但似乎沒有一個符合我的使用情況,所以如果這個問題已經在其他地方得到了答案,請原諒。
我有以下的XML例子(有多個檔案專案):
<doc>
<att>/span>
<PRef>/span>52545125</PRef>
< BlobContent Name="rtf" ID="A7A9348763A111EA887800505685156C">
< 屬性 名稱="MimeType" 值="application/rtf"/>
<Property Name="FileName" Value="P0001A__m。 rtf"/>
<Reference Link="Directoryexport_819280402327681192_P0001A__m.rtf"。
Type="RELATIVEFILE"/>>
</BlobContent>/span>
<InvoiceDate>01/1970</InvoiceDate>/span>
<NetAmount>/span>100.75</NetAmount>
<GrossAmount/>
< BlobContent Name="tif" ID="A7A90D7663A111EA887800505685156C">
< 屬性 名稱="MimeType" 值="image/tiff"/>
<Property Name="FileName" Value="P0001A__m. tif"/>
<Reference Link="Directoryexport_4747308861722121077_P0001A__m.tif"
Type="RELATIVEFILE"/>>
</BlobContent>/span>
</att>/span>
我試圖從每個BlobContent中改變如下內容
<Reference Link="Directoryexport_4747308861722121077_P0001A__m. tif" Type="RELATIVEFILE"/>。
讀作:
<rtf> Directoryexport_819280402327681192_P0001A__m. rtf</rtf>Directoryexport_8192402327681192_P0001A__m。
<tif>Directoryexport_4747308861722121077_P0001A__m.tif</tif>
下面的xsl將按預期作業,但將資料放入標簽中,沒有任何東西可以定義這是tif還是rtf:
<?xml version="1.0" encoding="UTF-8"? >
<xsl:styleheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"/span>
xmlns:xs="http://www.w3.org/2001/XMLSchema"。
exclude-result-prefixes="xs"/span>
version="2.0"/span>>
<xsl: output method="xml"/span> encoding="UTF-8"/span> indent="yes"/span>/>
<xsl:strip-space elements="*"/>
<xsl:template match="@*|node()"/span>>
<xsl:copy>
<xsl:apply-templates select="@*|node()"/span>/>
</xsl:copy>
</xsl:template>
<xsl:template match="/doc/att/BlobContent/Reference"/span>>
<xsl: 變數 name="element-name" select="@Link"/> select=
<xsl:element name="Link">/span>
<xsl:value-of select="@Link"/span>/>
</xsl: element>
</xsl:template>
</xsl:styleheet>/span>
我試著添加一個for-each來創建基于BlobContent名稱的新標簽,但得到一個錯誤,說明{tif rtf}是一個無效的QName,所以它似乎是在接收每個值,但將它們分組為一個單一的元素名稱。
謝謝你
uj5u.com熱心網友回復:
使用一個模板
<xsl: 模板 match="/doc/att/BlobContent/Reference"/span>>
<xsl:element name="{./@Name}">
<xsl:value-of select="@Link"/>
</xsl: element>
</xsl:team>
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/307717.html
標籤:
上一篇:在相同的檔案中查找并粘貼
