中获取价值并存储在变量中

中获取价值并存储在变量中

本文介绍了使用 XSLT 从 XML 中获取价值并存储在变量中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<Result>
  <resultDetails>
    <resultDetailsData>
      <itemProperties>
        <ID>1</ID>
        <type>LEVEL</type>
        <value xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" xsi:type="xs:int">5</value>
      </itemProperties>
    </resultDetailsData>
  </resultDetails>
</Result>

我有上面描述的 xml.我想使用类型标记的值(即本例中的 LEVEL)获取值标记的值(在本例中为5")并使用 XSLT 将其存储在变量中,以便我可以使用该变量稍后.

I have the xml described above. I want to get the value of value tag (in this case, '5') using the value of the type tag, (i.e., LEVEL in this case) and store it in a variable using XSLT, so that i can use the variable later.

知道该怎么做吗?

推荐答案

你可以这样做:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">

<xsl:template match="/">
    <xsl:variable name="myVar" select="Result/resultDetails/resultDetailsData/itemProperties/value"/>
<varoutput>
    <xsl:value-of select="$myVar"/>
</varoutput>
</xsl:template>

应用于您的输入 XML,您会得到以下输出:

Applied to your input XML you get this output:

<?xml version="1.0" encoding="UTF-8"?>
<varoutput>5</varoutput>

问候,彼得

这篇关于使用 XSLT 从 XML 中获取价值并存储在变量中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-07 02:56