この質問は実際に別のmy questionに関連しています。私は、サンプルxml、xsltスタイルシート、および変換されたXML出力ファイルを以下に示します。まず、出力ファイルに値を持たない要素を生成させたくないということです。 2つ目は、結果ファイルの最初のタグからこれらの名前空間宣言を削除したいということです。XSLT変換されたxmlの空の要素を削除します
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsse="http://schemas.xmlsoap.org/ws/2002/04/secext">
<soap:Body>
<InstantIDResponseEx xmlns="http://webservices.seisint.com/WsIdentity">
<response>
<Header>
<Status>0</Status>
<TransId>41904</TransId>
<User></User>
</Header>
<Result>
<Data/>
</Result>
</response>
</InstantIDResponseEx>
</soap:Body>
XSLTスタイルシート:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:Identity="http://webservices.seisint.com/WsIdentity"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:wsse="http://schemas.xmlsoap.org/ws/2002/04/secext" version="1.0">
<xsl:strip-space elements="*"/>
<!-- ****** MAIN TEMPLATE ******* -->
<xsl:template match="/">
<Verification_response>
<xsl:apply-templates select="/soap:Envelope/soap:Body/Identity:InstantIDResponseEx/Identity:response"/>
</Verification_response>
</xsl:template>
<xsl:template match = "Identity:response">
<System_Data>
<xsl:apply-templates select = "Identity:Header" />
</System_Data>
<Received>
<xsl:apply-templates select = "Identity:Result" />
</Received>
</xsl:template>
<xsl:template match="Identity:Header">
<STATUSMESSAGE>
<xsl:apply-templates select="Identity:Status"/>
</STATUSMESSAGE>
<TRANSACTIONID>
<xsl:apply-templates select="Identity:TransId"/>
</TRANSACTIONID>
<Client>
<xsl:apply-templates select="Identity:User"/>
</Client>
</xsl:template>
<xsl:template match="Identity:Result">
<Content>
<xsl:apply-templates select="Identity:Data"/>
</Content>
</xsl:template>
<xsl:template match="Identity:Status">
<xsl:value-of select="."/>
</xsl:template>
<xsl:template match="Identity:TransId">
<xsl:value-of select="."/>
</xsl:template>
<xsl:template match="Identity:User">
<xsl:value-of select="."/>
</xsl:template>
<xsl:template match="Identity:Data">
<xsl:value-of select="."/>
</xsl:template>
</xsl:stylesheet>
変換されたXML:
<Verification_response xmlns:Identity="http://webservices.seisint.com/WsIdentity"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:wsse="http://schemas.xmlsoap.org/ws/2002/04/secext">
<System_Data>
<STATUSMESSAGE>0</STATUSMESSAGE>
<TRANSACTIONID>41904</TRANSACTIONID>
<Client/>
</System_Data>
<Received>
<Content/>
</Received>
</Verification_response>
結果のXMLファイルは、この
<Verification_response>
<System_Data>
<STATUSMESSAGE>0</STATUSMESSAGE>
<TRANSACTIONID>41904</TRANSACTIONID>
</System_Data>
</Verification_response>
XML入力ファイルのようになります。
フォーラムの別の投稿からルートノードの前に次のコードを追加しようとしましたが、機能しませんでした。誰でもこの問題について助けてくれますか?
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match=
"*[not(node())]
|
*[not(node()[2])
and
node()/self::text()
and
not(normalize-space())
]
"/>