以下は私の要件です。
1) true と評価された特定の条件に基づいて、要素「エラー」を最後の要素として追加したい。2) true と評価された場合に、他の条件に基づいて要素「generic_quote_ind」を「quote_or_print」要素の直後に追加したい。
以下は、入力 XML、私が作成した XSLT、および期待される出力 XML です。
このコードを使用すると、「error」要素を の最後の要素として追加できますが、「quote_or_print」要素の直後に「generic_quote_ind」を追加できません。
これを達成する方法を教えてください。
入力 XML
<?xml version="1.0" encoding="utf-8"?>
<message xmlns="http://www.origoservices.com" xmlns:xsi="http://www.w3.org /2001/XMLSchema-instance">
<m_control>
<control_timestamp>2013-06-06T14:55:37</control_timestamp>
<initiator_id>ASL</initiator_id>
</m_control>
<m_content>
<b_control>
<quote_type>Comparison</quote_type>
<quote_or_print>Quote And Print</quote_or_print>
<message_version_number>3.7</message_version_number>
</b_control>
<application>
<product>
<tpsdata>
<service_type>QuickQuote</service_type>
<quote_type>Standard</quote_type>
</tpsdata>
</product>
</application>
</m_content>
</message>
期待されるアウトプット
<?xml version="1.0" encoding="UTF-8"?>
<message xmlns="http://www.origoservices.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<m_control>
<control_timestamp>2013-06-06T14:55:37</control_timestamp>
<initiator_id>ASL</initiator_id>
</m_control>
<m_content>
<b_control>
<quote_type>Comparison</quote_type>
<quote_or_print>Quote And Print</quote_or_print>
<generic_quote_ind>Yes</generic_quote_ind>
<message_version_number>3.7</message_version_number>
</b_control>
<application>
<product>
<tpsdata>
<service_type>QuickQuote</service_type>
<quote_type>Standard</quote_type>
</tpsdata>
</product>
</application>
</m_content>
</message>
試したXSLT
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:dp="http://www.datapower.com/extensions" xmlns:fn="http://www.w3.org/2005/xpath- functions" xmlns:date="http://exslt.org/dates-and-times" version="1.0" extension-element-prefixes="dp">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="*">
<!-- identity with closing tags -->
<xsl:element name="{name()}">
<xsl:apply-templates select="@*|node()"/>
</xsl:element>
</xsl:template>
<xsl:variable name="GenericQuoteInd">
<xsl:value-of select="/*[namespace-uri()='http://www.origoservices.com' and local- name()='message']/*[namespace-uri()='http://www.origoservices.com' and local-name()='m_content']/*[namespace-uri()='http://www.origoservices.com' and local-name()='b_control']/*[namespace-uri()='http://www.origoservices.com' and local-name()='generic_quote_ind']"/>
</xsl:variable>
<xsl:variable name="InitiatorId">
<xsl:value-of select="/*[namespace-uri()='http://www.origoservices.com' and local-name()='message']/*[namespace-uri()='http://www.origoservices.com' and local-name()='m_control']/*[namespace-uri()='http://www.origoservices.com' and local-name()='initiator_id']"/>
</xsl:variable>
<xsl:variable name="ServiceType">
<xsl:value-of select="/*[namespace-uri()='http://www.origoservices.com' and local-name()='message']/*[namespace-uri()='http://www.origoservices.com' and local-name()='m_content']/*[namespace-uri()='http://www.origoservices.com' and local-name()='application']/*[namespace-uri()='http://www.origoservices.com' and local-name()='product']/*[namespace-uri()='http://www.origoservices.com' and local-name()='tpsdata']/*[namespace-uri()='http://www.origoservices.com' and local-name()='service_type']"/>
</xsl:variable>
<xsl:variable name="quoteNPrint">
<xsl:value-of select="/*[namespace-uri()='http://www.origoservices.com' and local-name()='message']/*[namespace-uri()='http://www.origoservices.com' and local-name()='m_content']/*[namespace-uri()='http://www.origoservices.com' and local-name()='b_control']/*[namespace-uri()='http://www.origoservices.com' and local-name()='quote_or_print']"/>
</xsl:variable>
<xsl:template match="/*[namespace-uri()='http://www.origoservices.com' and local-name()='message']/*[namespace-uri()='http://www.origoservices.com' and local-name()='m_content']/*[namespace-uri()='http://www.origoservices.com' and local-name()='b_control']">
<xsl:choose>
<xsl:when test="(($GenericQuoteInd = 'Yes') or (($InitiatorId = 'ASL') and ($ServiceType='QuickQuote'))) and ($quoteNPrint='Quote And Print')">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
<xsl:element name="error" namespace="{namespace-uri()}">can not provide quotation</xsl:element>
</xsl:copy>
</xsl:when>
<xsl:when test="(($GenericQuoteInd = '') and (($InitiatorId = 'ASL') and ($ServiceType='QuickQuote'))) and ($quoteNPrint='QuoteOnly')">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
<xsl:element name="generic_quote_ind" namespace="{namespace-uri()}">Yes</xsl:element>
</xsl:copy>
</xsl:when>
<xsl:when test="($GenericQuoteInd = 'Yes') and ($quoteNPrint='QuoteOnly')">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:when>
<!--xsl:when test="($GenericQuoteInd = ' Yes') or (($InitiatorId = 'ASL') and ($ServiceType='QuickQuote')) and ($quoteNPrint='QuoteOnly')">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:when-->
<xsl:otherwise>
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
<xsl:element name="otherwise_loop" namespace="{namespace-uri()}">Yes</xsl:element>
</xsl:copy>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="*|comment()|processing-instruction()">
<xsl:copy>
<xsl:copy-of select="@*|namespace::*"/>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>