1
我想下面的XML變換:XSLT我如何擺脫多餘的不必要的OAuth標籤
<OAuth>
<audience>aabd69c9-6d97-4fdf-8bd5-80d0c8fb1ed4</audience>
<user_id>ABELG</user_id>
<scope>resource.WRITE resource.READ</scope>
<expires_in>3574</expires_in>
<return_code>200</return_code>
<return_message>Success</return_message>
</OAuth>
到下面:
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:ng3="https://myurl.com/OAuth">
<soap:Body>
<ng3:OAuth>
<ng3:client_id>aabd69c9-6d97-4fdf-8bd5-80d0c8fb1ed4</ng3:client_id>
<ng3:Username>ABELG</ng3:Username>
<ng3:scope>resource.WRITE resource.READ</ng3:scope>
<ng3:expires_in>3574</ng3:expires_in>
<ng3:return_code>200</ng3:return_code>
<ng3:return_message>Success</ng3:return_message>
</ng3:OAuth>
</soap:Body>
</soap:Envelope>
使用:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
xmlns:ng3="https://myurl.com/OAuth">
<xsl:output method="xml" />
<xsl:template match="OAuth">
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<xsl:element name="ng3:OAuth">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:element>
</soap:Body>
</soap:Envelope>
</xsl:template>
<xsl:template match="audience">
<xsl:element name="ng3:client_id">
<xsl:value-of select="."/>
</xsl:element>
</xsl:template>
<xsl:template match="user_id">
<xsl:element name="ng3:Username">
<xsl:value-of select="."/>
</xsl:element>
</xsl:template>
<xsl:template match="*">
<xsl:element name="ng3:{name()}">
<xsl:apply-templates select="node()|@*"/>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
但是,在進行轉換後,我得到了額外的不需要的OAuth標記(沒有名稱空間前綴的標記):
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:ng3="https://myurl.com/OAuth">
<soap:Body>
<ng3:OAuth>
<OAuth>
<ng3:client_id>aabd69c9-6d97-4fdf-8bd5-80d0c8fb1ed4</ng3:client_id>
<ng3:Username>ABELG</ng3:Username>
<ng3:scope>resource.WRITE resource.READ</ng3:scope>
<ng3:expires_in>3574</ng3:expires_in>
<ng3:return_code>200</ng3:return_code>
<ng3:return_message>Success</ng3:return_message>
</OAuth>
</ng3:OAuth>
</soap:Body>
</soap:Envelope>
當我設法擺脫額外的OAuth標籤,我失去了封閉的肥皂標籤。請幫助這位XSLT新手。
感謝棧 - 它的工作! –