メッセージ フィールドの文字長が 200 文字である DB に SOAP メッセージを挿入する必要があるという要件があります。これを実現するには XSLT を使用する必要があり、CDATA セクションで SoapMessage を取得しています。
以下は、CDATA タグ内の変数に格納する SOAP メッセージです。
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v4="http://www.example.com/ServiceBody/V4">
<soapenv:Header>
</soapenv:Header>
<soapenv:Body>
<v4:getBookDetails>
<v4:Request>
<catalog>
<book id="bk101">
<author>Gambardella, Matthew</author>
<title>XML Developer's Guide</title>
<genre>Computer</genre>
<price>44.95</price>
<publish_date>2000-10-01</publish_date>
<description>An in-depth look at creating applications with XML.</description>
</book>
</catalog>
</v4:Request>
</v4:getBookDetails>
</soapenv:Body>
</soapenv:Envelope>
以下は、DB に挿入できるようにメッセージを複数のタグに入れるために作成した XSLT です。
<xsl:stylesheet extension-element-prefixes="date str" exclude-result-prefixes="dp str date" version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:date="http://exslt.org/dates-and-times" xmlns:str="http://exslt.org/strings">
<xsl:output method="xml"/>
<xsl:template match="/">
<xsl:variable name="cdataVariable">
<xsl:text disable-output-escaping="yes"><![CDATA[</xsl:text>
<xsl:copy-of select="."/>
<xsl:text disable-output-escaping="yes">]]></xsl:text>
</xsl:variable>
<MessageInChunks>
<stringLength><xsl:value-of select="string-length($cdataVariable)"/></stringLength>
<xsl:choose>
<xsl:when test="string-length($cdataVariable) < 200">
<Chunks>
<xsl:copy-of select="$cdataVariable"/>
</Chunks>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="splitMessageIntoChunks">
<xsl:with-param name="messageToSplit">
<xsl:copy-of select="$cdataVariable"/>
</xsl:with-param>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</MessageInChunks>
</xsl:template>
<xsl:template name="splitMessageIntoChunks">
<xsl:param name="messageToSplit"/>
<xsl:variable name="chunkSize" select="'200'"/>
<xsl:if test="string-length($messageToSplit) >0">
<Chunks>
<xsl:text disable-output-escaping="yes"><![CDATA[</xsl:text>
<xsl:copy-of select="substring($messageToSplit, 12, $chunkSize)"/>
<xsl:text disable-output-escaping="yes">]]></xsl:text>
</Chunks>
<xsl:call-template name="splitMessageIntoChunks">
<xsl:with-param name="messageToSplit" select="substring($messageToSplit, $chunkSize+1)"/>
</xsl:call-template>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
しかし、部分文字列関数の出力が要素を表示していないため、取得している出力には値を期待する要素が含まれていません。
私はこのようなものが必要です。
<MessageInChunks>
<Chunks><![CDATA[<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v4="http://www.example.com/ServiceBody/V4">
<soapenv:Header>
</soapenv:Header>
<soapenv:Body>
<v4:getBookDet]]></Chunks>
<Chunks><![CDATA[ails>
<v4:Request>
<catalog>
<book id="bk101">
<author>Gambardella, Matthew</author>
<title>XML Developer's Guide</title>
<genre>Compu]]>
</Chunks>
<Chunks><![CDATA[ter</genre>
<price>44.95</price>
<publish_date>2000-10-01</publish_date>
<description>An in-depth look at creating applications with XML.</description>
]]>
</Chunks>
<Chunks><![CDATA[ </book>
</catalog>
</v4:Request>
</v4:getBookDetails>
</soapenv:Body>
</soapenv:Envelope>]]>
</Chunks>
</MessageInChunks>
基本的に必要なのは、XML メッセージを 200 文字のチャンクに分割し、XSLT を使用して CDATA セクションに入れることです。
この問題で私を助けてください。