0
我是XSLT的新手,負責XML到XML的轉換。我想根據條件在xml中添加一個元素。如何使用XSLT在XML中插入新元素
我有這個員工的信息和要求是在每個員工的元素內添加標籤。
**Scenario1**
<Employee>
<Name>Check1</Name>
<Position>
<org>
<orgName>COMPANY</orgName>
<orgType>ABC</orgTyp>
<org>
</Position>
</Employee>
**Scenario2**
<Employee>
<Name>Nitesh</Name>
<Position>
<role>Consultant</role>
</Position>
</Employee>
**Scenario3**
<Employee>
<Name>Nitesh</Name>
</Employee>
我寫了下面的代碼,但它沒有給我想要的輸出。
`
<xsl:when test="not(xs:Position)">
<xsl:copy>
<!-- And everything inside it -->
<xsl:apply-templates select="@* | node()"/>
<!-- Add node -->
<xs:Position>
<xs:Organization>
<xs:Organization_Type>1<xsl:value-of select="$OrgType"/>
</xs:Organization_Type>
<xs:Organization_Code>2<xsl:value-of select="$OrgCode"/>
</xs:Organization_Code>
<xs:Organization_Name>3<xsl:value-of select="$OrgName"/>
</xs:Organization_Name>
</xs:Organization>
</xs:Position>
</xsl:copy>
</xsl:when>
<xsl:when test="xs:Position">
<xsl:variable name="element" select="xs:Position"/>
<xsl:choose>
<xsl:when test="not(xs:Position/xs:Organization/xs:Organization_Type='COMPANY')">
<xs:Organization>
<xs:Organization_Type>1<xsl:value-of select="$OrgType"/>
</xs:Organization_Type>
<xs:Organization_Code>2<xsl:value-of select="$OrgCode"/>
</xs:Organization_Code>
<xs:Organization_Name>3<xsl:value-of select="$OrgName"/>
</xs:Organization_Name>
</xs:Organization>
<xsl:copy-of select="$element"/>
</xsl:when>
</xsl:choose>
</xsl:when>`
什麼是每個方案預期的結果? –
類似於情景1的輸出 –
「*類似情景1的輸出*」真的嗎?所以你不想在場景#2中輸出'顧問 '節點? –