Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/14.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
XML/XSL:如何比较两个节点并根据比较设置另一个节点的值?_Xml_Xslt_Compare_Nodes - Fatal编程技术网

XML/XSL:如何比较两个节点并根据比较设置另一个节点的值?

XML/XSL:如何比较两个节点并根据比较设置另一个节点的值?,xml,xslt,compare,nodes,Xml,Xslt,Compare,Nodes,关于XML和XSL的一个问题 (我正在使用sharepoint 2007) 如何比较两个节点 在下面的例子中,我想比较“促销价格”和“价格” 如果“促销价格”等于或大于“价格”,则“确定”应为“否”。 如果“促销价格”小于“价格”,则“确定”应为“是” 我不确定我是否使用了正确的语法,因为在sharepoint中它不起作用,它总是给出“是” XML example: <?xml version="1.0" encoding="ISO-8859-1" ?> <catalog&

关于XML和XSL的一个问题 (我正在使用sharepoint 2007)

如何比较两个节点

在下面的例子中,我想比较“促销价格”和“价格”

如果“促销价格”等于或大于“价格”,则“确定”应为“否”。 如果“促销价格”小于“价格”,则“确定”应为“是”

我不确定我是否使用了正确的语法,因为在sharepoint中它不起作用,它总是给出“是”

XML example:

<?xml version="1.0" encoding="ISO-8859-1" ?> 
<catalog>
<cd>
<title>Empire Burlesque</title> 
<artist>Bob Dylan</artist> 
<country>USA</country> 
<company>Columbia</company> 
<price>10.90</price>
<promotionprice>15.00</promotionprice>
<year>1985</year> 
<OK>Yes</OK>
</cd>
<cd>
<title>Hide your heart</title> 
<artist>Bonnie Tyler</artist> 
<country>UK</country> 
<company>CBS Records</company> 
<price>9.90</price> 
<promotionprice>5.00</promotionprice>
<year>1988</year> 
<OK>Yes</OK>
</cd>
</catalog>


XSL example:
...
<!-- title node -->
<td>
<xsl:value-of select="@title"/>
</td>
<!-- artist node -->
<td>
<xsl:value-of select="@artist"/>
</td>
...
<!-- OK node -->
<td>
<xsl:choose>
<xsl:when test="promotionprice &gt;= price">
<xsl:value-of select="'NO'"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="'YES'"/>
</xsl:otherwise>
</xsl:choose>
</td>

WANTED RESULT:
<table border="1">
<tr>
  <td>Empire Burlesque</td>
  <td>Bob Dylan</td>
  <td>USA</td>
  <td>Columbia</td>
  <td>10.90</td>
  <td>15.00</td>
  <td>1985</td>
  <td>NO</td>
</tr>
<tr>
  <td>Hide your heart</td>
  <td>Bonnie Tyler</td>
  <td>UK</td>
  <td>CBS Records</td>
  <td>9.90</td>
  <td>5.00</td>
  <td>1988</td>
  <td>YES</td>
</tr>
</table>
XML示例:
帝国滑稽剧
鲍勃·迪伦
美国
哥伦比亚
10.90
15
1985
对
隐藏你的心
邦妮·泰勒
英国
哥伦比亚广播公司唱片
9.90
5
1988
对
XSL示例:
...
...
通缉结果:
皇帝讽刺剧
鲍勃·迪伦
美国
哥伦比亚
10.90
15
1985
不
隐藏你的心
邦尼泰勒
英国
哥伦比亚唱片公司
9.90
5
1988
对

提前多谢

此转换:

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

 <xsl:template match="/*">
     <table border="1">
      <xsl:apply-templates/>
     </table>
 </xsl:template>

 <xsl:template match="cd">
   <tr><xsl:apply-templates/></tr>
 </xsl:template>

 <xsl:template match="title|artist">
  <td><xsl:value-of select="."/></td>
 </xsl:template>

 <xsl:template match="OK">
  <td>
   <xsl:value-of select=
    "substring('YESNO', 4 -3*(../price >= ../promotionprice),3)"/>
  </td>
 </xsl:template>
 <xsl:template match="text()"/>
</xsl:stylesheet>
<catalog>
    <cd>
        <title>Empire Burlesque</title>
        <artist>Bob Dylan</artist>
        <country>USA</country>
        <company>Columbia</company>
        <price>10.90</price>
        <promotionprice>15.00</promotionprice>
        <year>1985</year>
        <OK>Yes</OK>
    </cd>
    <cd>
        <title>Hide your heart</title>
        <artist>Bonnie Tyler</artist>
        <country>UK</country>
        <company>CBS Records</company>
        <price>9.90</price>
        <promotionprice>5.00</promotionprice>
        <year>1988</year>
        <OK>Yes</OK>
    </cd>
</catalog>

应用于提供的XML文档时

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

 <xsl:template match="/*">
     <table border="1">
      <xsl:apply-templates/>
     </table>
 </xsl:template>

 <xsl:template match="cd">
   <tr><xsl:apply-templates/></tr>
 </xsl:template>

 <xsl:template match="title|artist">
  <td><xsl:value-of select="."/></td>
 </xsl:template>

 <xsl:template match="OK">
  <td>
   <xsl:value-of select=
    "substring('YESNO', 4 -3*(../price >= ../promotionprice),3)"/>
  </td>
 </xsl:template>
 <xsl:template match="text()"/>
</xsl:stylesheet>
<catalog>
    <cd>
        <title>Empire Burlesque</title>
        <artist>Bob Dylan</artist>
        <country>USA</country>
        <company>Columbia</company>
        <price>10.90</price>
        <promotionprice>15.00</promotionprice>
        <year>1985</year>
        <OK>Yes</OK>
    </cd>
    <cd>
        <title>Hide your heart</title>
        <artist>Bonnie Tyler</artist>
        <country>UK</country>
        <company>CBS Records</company>
        <price>9.90</price>
        <promotionprice>5.00</promotionprice>
        <year>1988</year>
        <OK>Yes</OK>
    </cd>
</catalog>

皇帝讽刺剧
鲍勃·迪伦
美国
哥伦比亚
10.90
15
1985
对
隐藏你的心
邦尼泰勒
英国
哥伦比亚唱片公司
9.90
5
1988
对
产生我想是想要的结果:

<table border="1">
   <tr>
      <td>Empire Burlesque</td>
      <td>Bob Dylan</td>
      <td>NO</td>
   </tr>
   <tr>
      <td>Hide your heart</td>
      <td>Bonnie Tyler</td>
      <td>YES</td>
   </tr>
</table>

皇帝讽刺剧
鲍勃·迪伦
不
隐藏你的心
邦尼泰勒
对

此转换:

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

 <xsl:template match="/*">
     <table border="1">
      <xsl:apply-templates/>
     </table>
 </xsl:template>

 <xsl:template match="cd">
   <tr><xsl:apply-templates/></tr>
 </xsl:template>

 <xsl:template match="title|artist">
  <td><xsl:value-of select="."/></td>
 </xsl:template>

 <xsl:template match="OK">
  <td>
   <xsl:value-of select=
    "substring('YESNO', 4 -3*(../price >= ../promotionprice),3)"/>
  </td>
 </xsl:template>
 <xsl:template match="text()"/>
</xsl:stylesheet>
<catalog>
    <cd>
        <title>Empire Burlesque</title>
        <artist>Bob Dylan</artist>
        <country>USA</country>
        <company>Columbia</company>
        <price>10.90</price>
        <promotionprice>15.00</promotionprice>
        <year>1985</year>
        <OK>Yes</OK>
    </cd>
    <cd>
        <title>Hide your heart</title>
        <artist>Bonnie Tyler</artist>
        <country>UK</country>
        <company>CBS Records</company>
        <price>9.90</price>
        <promotionprice>5.00</promotionprice>
        <year>1988</year>
        <OK>Yes</OK>
    </cd>
</catalog>

应用于提供的XML文档时

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

 <xsl:template match="/*">
     <table border="1">
      <xsl:apply-templates/>
     </table>
 </xsl:template>

 <xsl:template match="cd">
   <tr><xsl:apply-templates/></tr>
 </xsl:template>

 <xsl:template match="title|artist">
  <td><xsl:value-of select="."/></td>
 </xsl:template>

 <xsl:template match="OK">
  <td>
   <xsl:value-of select=
    "substring('YESNO', 4 -3*(../price >= ../promotionprice),3)"/>
  </td>
 </xsl:template>
 <xsl:template match="text()"/>
</xsl:stylesheet>
<catalog>
    <cd>
        <title>Empire Burlesque</title>
        <artist>Bob Dylan</artist>
        <country>USA</country>
        <company>Columbia</company>
        <price>10.90</price>
        <promotionprice>15.00</promotionprice>
        <year>1985</year>
        <OK>Yes</OK>
    </cd>
    <cd>
        <title>Hide your heart</title>
        <artist>Bonnie Tyler</artist>
        <country>UK</country>
        <company>CBS Records</company>
        <price>9.90</price>
        <promotionprice>5.00</promotionprice>
        <year>1988</year>
        <OK>Yes</OK>
    </cd>
</catalog>

皇帝讽刺剧
鲍勃·迪伦
美国
哥伦比亚
10.90
15
1985
对
隐藏你的心
邦尼泰勒
英国
哥伦比亚唱片公司
9.90
5
1988
对
产生我想是想要的结果:

<table border="1">
   <tr>
      <td>Empire Burlesque</td>
      <td>Bob Dylan</td>
      <td>NO</td>
   </tr>
   <tr>
      <td>Hide your heart</td>
      <td>Bonnie Tyler</td>
      <td>YES</td>
   </tr>
</table>

皇帝讽刺剧
鲍勃·迪伦
不
隐藏你的心
邦尼泰勒
对
请编辑问题并提供转换所需的准确结果。请编辑问题并提供转换所需的准确结果。
子字符串()的+1而不是
xsl:choose
@dee ln-如果您将
match=“title | artist”
更改为
match=“*”
并删除
,您将获得所需的输出。
子字符串()
的+1,而不是
xsl:choose
@dee ln-如果您将
match=“title | artist”
更改为
match=“*”
并删除
,您将获得您想要的输出。