[英]How can I produce this XML document using an XSLT transformation?
Original XML:原始 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.我想将 type="group" 属性添加到父标签。
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请使用下面的代码,只需匹配模板并添加@type 属性
<?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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.