ここにいるメンバーからの寛大なフィードバックのおかげで、XML から XML へのプロジェクトで大きな進歩を遂げることができました。
そうは言っても、プロジェクトの最終バージョンで 2 つの問題が発生しており、これらの問題が発生している理由をよりよく理解したいと考えています。
最初に、複数の値で構成された連結要素値を作成する必要があります。次のコードを使用してこれを機能させています。
<xsl:template match="estimate/JobParts/JobPart/description">
<description>
<xsl:value-of select="concat(estimate/description,'_QTY-',estimate/JobParts/JobPart/qtyOrdered,'_',estimate/JobParts/JobPart/itemTemplate)"/>
</description>
</xsl:template>
これにより、 のすべての一致が検出estimate/JobParts/JobPart/description
されますが、すべての場合において、説明の値を置き換えるときに、最初に一致した兄弟要素の値のみが使用されます。
これは、イテレーションを管理するためにキーを使用する必要がある状況ですか? もしそうなら、キーを作成するにはどうすればよいですか? 反復管理を自動的に処理できるように、適用テンプレートを使用してこれを処理する別の方法はありますか?もしそうなら、それはどのように構築されますか?
私が抱えているもう1つの問題は、CDATA指定を要素に手動で追加する必要があり、その要素をcdata-section-elementsのリストに追加できないことです。これは、同じ名前の別の要素がドキュメント構造のより深くネストされているためです。 CDATA 指定を必要としません。
CDATA フラグを手動で追加するために使用しようとしているコードは次のとおりです。
<xsl:template match="estimate/description">
<description>
<xsl:text disable-output-escaping="yes">
<![CDATA[
</xsl:text>
<xsl:value-of select="estimate/description"/>
<xsl:text disable-output-escaping="yes">
]]>
</xsl:text>
</description>
</xsl:template>
興味深いことに、これはターゲットの説明要素にはまったく影響しません。
これらの変換のいずれか (または両方) が正しく機能しない理由を誰かが考えている場合は、学び、理解したいと思っています。
コードの集中砲火について事前に謝罪しますが、元の XML は次のとおりです。
<?xml version="1.0"?>
<PODOrderSheet_Main>
<estimate>
<customer>LINFNC</customer>
<newJob>Y</newJob>
<incrementJobVersion>Y</incrementJobVersion>
<description><![CDATA[409511]]></description>
<billPartsTogether>1</billPartsTogether>
<dateSetup><![CDATA[4/24/2013]]></dateSetup>
<promiseDate><![CDATA[4/24/2013]]></promiseDate>
<scheduledShipDate><![CDATA[4/24/2013]]></scheduledShipDate>
<adminStatus>O</adminStatus>
<shipVia>1</shipVia>
<jobType>5020</jobType>
<poNum><![CDATA[409511]]></poNum>
<itemTemplate><![CDATA[33503MN_0212]]></itemTemplate>
<JobParts>
<JobPart>
<jobPart>01</jobPart>
<contactNum/>
<description><![CDATA[REPLACEMENT OF LIFE INSURANCE OR ANNUITIES MINNESOTA]]></description>
<productionStatus>O</productionStatus>
<qtyOrdered><![CDATA[3]]></qtyOrdered>
<shipToContact/>
<itemTemplate><![CDATA[33503MN_0212]]></itemTemplate>
<JobNotes>
<JobNote>
<department>001</department>
<jobPart>01</jobPart>
<note><![CDATA[Rush Order]]></note>
</JobNote>
</JobNotes>
</JobPart>
</JobParts>
</estimate>
<estimate>
<customer>LINFNC</customer>
<newJob>Y</newJob>
<incrementJobVersion>Y</incrementJobVersion>
<description><![CDATA[409511]]></description>
<billPartsTogether>1</billPartsTogether>
<dateSetup><![CDATA[4/24/2013]]></dateSetup>
<promiseDate><![CDATA[4/24/2013]]></promiseDate>
<scheduledShipDate><![CDATA[4/24/2013]]></scheduledShipDate>
<adminStatus>O</adminStatus>
<shipVia>1</shipVia>
<jobType>5020</jobType>
<poNum><![CDATA[409511]]></poNum>
<itemTemplate><![CDATA[AL-FSC-FST068_Z08]]></itemTemplate>
<JobParts>
<JobPart>
<jobPart>01</jobPart>
<contactNum/>
<description><![CDATA[AMERICAN LEGACY III C SHARE FACT SHEET ]]></description>
<productionStatus>O</productionStatus>
<qtyOrdered><![CDATA[1]]></qtyOrdered>
<shipToContact/>
<itemTemplate><![CDATA[AL-FSC-FST068_Z08]]></itemTemplate>
<JobNotes>
<JobNote>
<department>001</department>
<jobPart>01</jobPart>
<note><![CDATA[Rush Order]]></note>
</JobNote>
</JobNotes>
</JobPart>
</JobParts>
</estimate>
<estimate>
<customer>LINFNC</customer>
<newJob>Y</newJob>
<incrementJobVersion>Y</incrementJobVersion>
<description><![CDATA[409511]]></description>
<billPartsTogether>1</billPartsTogether>
<dateSetup><![CDATA[4/24/2013]]></dateSetup>
<promiseDate><![CDATA[4/24/2013]]></promiseDate>
<scheduledShipDate><![CDATA[4/24/2013]]></scheduledShipDate>
<adminStatus>O</adminStatus>
<shipVia>1</shipVia>
<jobType>5020</jobType>
<poNum><![CDATA[409511]]></poNum>
<itemTemplate><![CDATA[AN06819-AL3C_1012]]></itemTemplate>
<JobParts>
<JobPart>
<jobPart>01</jobPart>
<contactNum/>
<description><![CDATA[AMERICAN LEGACY III C SHARE APPLICATION SUPPLEMENT - MULTI-STATE]]></description>
<productionStatus>O</productionStatus>
<qtyOrdered><![CDATA[1]]></qtyOrdered>
<shipToContact/>
<itemTemplate><![CDATA[AN06819-AL3C_1012]]></itemTemplate>
<JobNotes>
<JobNote>
<department>001</department>
<jobPart>01</jobPart>
<note><![CDATA[Rush Order]]></note>
</JobNote>
</JobNotes>
</JobPart>
</JobParts>
</estimate>
</PODOrderSheet_Main>
そして、ここに目的の出力があります:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE estimate>
<estimate>
<customer>LINFNC</customer>
<newJob>Y</newJob>
<incrementJobVersion>Y</incrementJobVersion>
<description><![CDATA[409511]]></description>
<billPartsTogether>1</billPartsTogether>
<dateSetup><![CDATA[4/24/2013]]></dateSetup>
<promiseDate><![CDATA[4/24/2013]]></promiseDate>
<scheduledShipDate><![CDATA[4/24/2013]]></scheduledShipDate>
<adminStatus>O</adminStatus>
<shipVia>1</shipVia>
<jobType>5020</jobType>
<poNum><![CDATA[409511]]></poNum>
<itemTemplate><![CDATA[33503MN_0212]]></itemTemplate>
<JobParts>
<JobPart>
<jobPart>01</jobPart>
<contactNum/>
<description>409511_QTY-3_33503MN_0212</description>
<priority>1</priority>
<productionStatus>O</productionStatus>
<qtyOrdered><![CDATA[3]]></qtyOrdered>
<shipToContact/>
<itemTemplate><![CDATA[33503MN_0212]]></itemTemplate>
<JobNotes>
<JobNote>
<department>001</department>
<jobPart>01</jobPart>
<note><![CDATA[Rush Order]]></note>
</JobNote>
</JobNotes>
</JobPart>
<JobPart>
<jobPart>02</jobPart>
<contactNum/>
<description>409511_QTY-1_AL-FSC-FST068_Z08</description>
<priority>1</priority>
<productionStatus>O</productionStatus>
<qtyOrdered><![CDATA[1]]></qtyOrdered>
<shipToContact/>
<itemTemplate><![CDATA[AL-FSC-FST068_Z08]]></itemTemplate>
<JobNotes>
<JobNote>
<department>001</department>
<jobPart>02</jobPart>
<note><![CDATA[Rush Order]]></note>
</JobNote>
</JobNotes>
</JobPart>
<JobPart>
<jobPart>03</jobPart>
<contactNum/>
<description>409511_QTY-1_AN06819-AL3C_1012</description>
<priority>1</priority>
<productionStatus>O</productionStatus>
<qtyOrdered><![CDATA[1]]></qtyOrdered>
<shipToContact/>
<itemTemplate><![CDATA[AN06819-AL3C_1012]]></itemTemplate>
<JobNotes>
<JobNote>
<department>001</department>
<jobPart>03</jobPart>
<note><![CDATA[Rush Order]]></note>
</JobNote>
</JobNotes>
</JobPart>
</JobParts>
</estimate>
現在の XSL は次のとおりです。
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output indent="yes" encoding="UTF-8" method="xml"/>
<xsl:strip-space elements="*"/>
<xsl:output cdata-section-elements="dateSetup promiseDate scheduledShipDate poNum qtyOrdered itemTemplate note"/>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
<xsl:template match="/PODOrderSheet_Main">
<estimate>
<xsl:copy-of select="estimate[1]/customer"/>
<xsl:copy-of select="estimate[1]/newJob"/>
<xsl:copy-of select="estimate[1]/incrementJobVersion"/>
<xsl:copy-of select="estimate[1]/description"/>
<xsl:copy-of select="estimate[1]/billPartsTogether"/>
<xsl:copy-of select="estimate[1]/dateSetup"/>
<xsl:copy-of select="estimate[1]/promiseDate"/>
<xsl:copy-of select="estimate[1]/scheduledShipDate"/>
<xsl:copy-of select="estimate[1]/adminStatus"/>
<xsl:copy-of select="estimate[1]/shipVia"/>
<xsl:copy-of select="estimate[1]/jobType"/>
<xsl:copy-of select="estimate[1]/poNum"/>
<xsl:copy-of select="estimate[1]/itemTemplate"/>
<JobParts>
<xsl:apply-templates select="estimate/JobParts/JobPart"/>
</JobParts>
</estimate>
</xsl:template>
<xsl:template match="estimate/description">
<description>
<xsl:text disable-output-escaping="yes">
<![CDATA[
</xsl:text>
<xsl:value-of select="estimate/description"/>
<xsl:text disable-output-escaping="yes">
]]>
</xsl:text>
</description>
</xsl:template>
<xsl:template match="//estimate/JobParts/JobPart/description">
<description>
<xsl:value-of select="concat(//estimate/description,'_QTY-',//JobPart/qtyOrdered,'_',//JobPart/itemTemplate)"/>
</description>
</xsl:template>
<xsl:template match="jobPart">
<xsl:copy><xsl:number count="JobPart" level="any" format="01"/></xsl:copy>
</xsl:template>
</xsl:stylesheet>
どうもありがとう...