Original XML:
<EbsSendOTPResponse>
<ResponseHeader>
<GUID/>
<GUID2/>
</ResponseHeader>
</EbsSendOTPResponse>
Transformed to:
<EbsSendOTPResponse type="group">
<ResponseHeader type="group">
<GUID/>
<GUID2/>
</ResponseHeader>
</EbsSendOTPResponse>
I want to add the type="group" attiribute to the parent tags.
You can try this:
<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>
Please use this below code, just match the template and add the @type attribute
<?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>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.