0
如何在xsl的幫助下刪除xml中的子元素,節點和父元素。如何在xsl的幫助下移除xml元素?
這裏是我的xml代碼。
<?xml version="1.0" encoding="UTF-8"?>
<Checkpax xmlns="http://xml.api.com/test">
<customerLevel>
<surname>MUKHERJEE</surname>
<type>A</type>
<gender>M</gender>
<otherPaxDetails>
<givenName>JOY</givenName>
<title>MR</title>
<age>11</age>
</otherPaxDetails>
<otherPaxDetails>
<title>MR</title>
</otherPaxDetails>
<staffDetails>
<staffInfo/>
<staffCategoryInfo>
<attributeDetails>
<attributeType>NA</attributeType>
</attributeDetails>
</staffCategoryInfo>
</staffDetails>
<productLevel>
<legLevel>
<legLevelIndicator>
<statusDetails>
<indicator>abc</indicator>
<action>1</action>
</statusDetails>
</legLevelIndicator>
</legLevel>
</productLevel>
<CustomerLevel>
<legLevel>
<legLevelIndicator>
<statusDetails>
<indicator>cde</indicator>
<action>1</action>
</statusDetails>
</legLevelIndicator>
</legLevel>
</CustomerLevel>
</customerLevel>
</Checkpax>
預期輸出XML:
<Checkpax xmlns="http://xml.api.com/test">
<paxDetails>
<surname>MUKHERJEE</surname>
<gender>M</gender>
</paxDetails>
<otherPaxDetails>
<title>MR</title>
<age>11</age>
</otherPaxDetails>
<otherPaxDetails>
<title>MR</title>
</otherPaxDetails>
<staffDetails>
<staffCategoryInfo>
<attributeDetails>
<attributeType>NA</attributeType>
</attributeDetails>
</staffCategoryInfo>
</staffDetails>
<legLevelIndicator>
<statusDetails>
<indicator>abc</indicator>
</statusDetails>
</legLevelIndicator>
<CustomerLevel>
<legLevel>
<legLevelIndicator>
<indicator>cde</indicator>
<action>1</action>
</legLevelIndicator>
</legLevel>
</CustomerLevel>
</Checkpax>
我從我的最終嘗試的XSL:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://xml.api.com/test"
xmlns:ns0="http://xml.api.com/test"
exclude-result-prefixes="ns0">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>
<!-- Identity transform -->
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<!-- Apply all child nodes; don't copy the element itself -->
<xsl:template match="ns0:customerLevel| ns0:customerDetails| ns0:paxDetails">
<xsl:apply-templates/>
</xsl:template>
</xsl:stylesheet>
請建議的XSL樣式表爲獲得預期的XML output.i不知道的讓人想起如何去除元素。這對於許多正在尋找xml中元素去除的人來說很有用。
給我一些建議,如何去除otherPaxDetails元素下的標籤@ michael.hor257k – sathya
@vidya見編輯我的帖子。 –
是的,這是有用的。我爲我工作。我會標記它。@ michael.hor257k – sathya