我是xsl转换的初学者
我有一些xml,当该属性不存在时,我需要将一个属性插入元素.
以下面的xml为例.
<Order Id="IR1598756" Status="2">
<Details>
<SomeInfo>Sample Data</SomeInfo>
</Details>
<Documents>
<Invoice>
<Date>15-02-2011</Date>
<Time>11:22</Time>
<Employee Id="159">James Morrison</Employee>
</Invoice>
<DeliveryNote>
<Reference>DN1235588</Reference>
<HoldingRef>HR1598785</HoldingRef>
<Date>16-02-2011</Date>
<Time>15:00</Time>
<Employee Id="25">Javi Cortez</Employee>
</DeliveryNote>
</Documents>
</Order>
Run Code Online (Sandbox Code Playgroud)
期望的输出
<Order Id="IR1598756" Status="2">
<Details>
<SomeInfo>Sample Data</SomeInfo>
</Details>
<Documents>
<Invoice Id="DN1235588">
<Date>15-02-2011</Date>
<Time>11:22</Time>
<Employee Id="159">James Morrison</Employee>
</Invoice>
</Documents>
</Order>
Run Code Online (Sandbox Code Playgroud)
该<Invoice>元素可以具有Id属性<Invoice Id="IR1564897">
我该如何检查以下内容.
<Refernce>DN1235588</Reference>作为Id<Reference>使用的价值<HoldingRef>HR1598785</HoldingRef> 我正在考虑实现类似以下内容
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="/">
<xsl:apply-templates select="//Order"/>
</xsl:template> …Run Code Online (Sandbox Code Playgroud) xslt ×1