原始XML:
<EbsSendOTPResponse>
<ResponseHeader>
<GUID/>
<GUID2/>
</ResponseHeader>
</EbsSendOTPResponse>
已转换为:
<EbsSendOTPResponse type="group">
<ResponseHeader type="group">
<GUID/>
<GUID2/>
</ResponseHeader>
</EbsSendOTPResponse>
我想将type =“ group”服装添加到父标签。
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:if test="*">
<!--
<xsl:if test="name()='ResponseHeader' or name()='EbsSendOTPResponse'">
-->
<xsl:attribute name="type">group</xsl:attribute>
</xsl:if>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="xs"
version="2.0">
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="EbsSendOTPResponse">
<EbsSendOTPResponse typpe="group">
<xsl:apply-templates/>
</EbsSendOTPResponse>
</xsl:template>
<xsl:template match="ResponseHeader">
<ResponseHeader typpe="group">
<xsl:apply-templates/>
</ResponseHeader>
</xsl:template>
</xsl:stylesheet>