[英]How can I produce this XML document using an XSLT transformation?
原始 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>
請使用下面的代碼,只需匹配模板並添加@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.