Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/blackberry/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用XSLT在特定条件下转换XML_Xslt - Fatal编程技术网

使用XSLT在特定条件下转换XML

使用XSLT在特定条件下转换XML,xslt,Xslt,以下是我的要求 1) 我希望根据计算为true的特定条件,将元素“error”添加为中的最后一个元素。 2) 如果计算结果为true,我希望在“quote”或“print”元素之后添加一个元素“generic” 下面是我编写的输入XML、XSLT和预期的输出XML 使用这段代码,我可以添加'error'元素作为中的最后一个元素,但我无法在'quote\u或\u print'元素之后添加'generic\u quote\u ind' 请指导我如何才能做到这一点 输入XML <?xml ve

以下是我的要求

1) 我希望根据计算为true的特定条件,将元素“error”添加为中的最后一个元素。 2) 如果计算结果为true,我希望在“quote”或“print”元素之后添加一个元素“generic”

下面是我编写的输入XML、XSLT和预期的输出XML

使用这段代码,我可以添加'error'元素作为中的最后一个元素,但我无法在'quote\u或\u print'元素之后添加'generic\u quote\u 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>

2013-06-06T14:55:37
ASL
比较
引用和打印
3.7
快速报价
标准
预期产出

<?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>

2013-06-06T14:55:37
ASL
比较
引用和打印
对
3.7
快速报价
标准
我尝试过的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>

无法提供报价
对
对
试试这个

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                              xmlns:o="http://www.origoservices.com"
                              exclude-result-prefixes="xsl o">
<xsl:output omit-xml-declaration="yes" indent="yes" />
<xsl:strip-space elements="*" />

<xsl:template match="@*|node()" name="ident">
 <xsl:copy>
  <xsl:apply-templates select="@*|node()" />
 </xsl:copy>
</xsl:template>

<xsl:template match="o:b_control[
    ((../../o:m_control/o:initiator_id='ASK') or (o:generic_quote_ind='Yes')) and
    (../o:application/o:tpsdata/o:service_type='QuickResponse') and
    (o:quote_or_print='Quote And Print')]">
 <xsl:copy>
  <xsl:apply-templates select="@*|node()" />
  <error xmlns="http://www.origoservices.com">unable to provide quote</error> 
 </xsl:copy>
</xsl:template>

<xsl:template match="o:b_control[
    ((../../o:m_control/o:initiator_id='ASK') or (o:generic_quote_ind='Yes')) and
    (../o:application/o:tpsdata/o:service_type='QuickResponse') and
    (o:quote_or_print='Quote Only')]
    [not( o:generic_quote_ind)]">
 <xsl:copy>
  <xsl:apply-templates select="@*|node()" />
  <generic_quote_ind xmlns="http://www.origoservices.com">Yes</generic_quote_ind> 
 </xsl:copy>
</xsl:template>

</xsl:stylesheet>

无法提供报价
对
试试这个

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                              xmlns:o="http://www.origoservices.com"
                              exclude-result-prefixes="xsl o">
<xsl:output omit-xml-declaration="yes" indent="yes" />
<xsl:strip-space elements="*" />

<xsl:template match="@*|node()" name="ident">
 <xsl:copy>
  <xsl:apply-templates select="@*|node()" />
 </xsl:copy>
</xsl:template>

<xsl:template match="o:b_control[
    ((../../o:m_control/o:initiator_id='ASK') or (o:generic_quote_ind='Yes')) and
    (../o:application/o:tpsdata/o:service_type='QuickResponse') and
    (o:quote_or_print='Quote And Print')]">
 <xsl:copy>
  <xsl:apply-templates select="@*|node()" />
  <error xmlns="http://www.origoservices.com">unable to provide quote</error> 
 </xsl:copy>
</xsl:template>

<xsl:template match="o:b_control[
    ((../../o:m_control/o:initiator_id='ASK') or (o:generic_quote_ind='Yes')) and
    (../o:application/o:tpsdata/o:service_type='QuickResponse') and
    (o:quote_or_print='Quote Only')]
    [not( o:generic_quote_ind)]">
 <xsl:copy>
  <xsl:apply-templates select="@*|node()" />
  <generic_quote_ind xmlns="http://www.origoservices.com">Yes</generic_quote_ind> 
 </xsl:copy>
</xsl:template>

</xsl:stylesheet>

无法提供报价
对

请展示您迄今为止所做的尝试。您好,我已经用迄今为止尝试过的XSLT更新了我的问题。很好。。。你能显示期望的输出和实际的输出吗?另外,您可以显示更多的输入XML吗?缺少它的一个关键部分,
打开标记上可能有一个默认名称空间声明。仅供参考,您可以通过在
元素上声明origoservices名称空间来避免很多麻烦:
xmlns:origo=”http://www.origoservices.com“
,使用这个前缀而不是关于名称空间uri和本地名称的谓词:
。您的XML列表是一堆难看的东西,很难阅读。请使用类似于使您的列表可读的服务。请显示您迄今为止所做的尝试。您好,我已使用迄今为止尝试过的XSLT更新了我的问题。很好。。。你能显示期望的输出和实际的输出吗?另外,您可以显示更多的输入XML吗?缺少它的一个关键部分,
打开标记上可能有一个默认名称空间声明。仅供参考,您可以通过在
元素上声明origoservices名称空间来避免很多麻烦:
xmlns:origo=”http://www.origoservices.com“
,使用这个前缀而不是关于名称空间uri和本地名称的谓词:
。您的XML列表是一堆难看的东西,很难阅读。请使用类似的服务使您的列表可读。