给出的 XML:
<?xml version="1.0" encoding="UTF-8"?>
<sensor-system>
<velocity>120.00</velocity> <!-- km/h -->
<temperature location="inside">24.6</temperature>
<temperature location="outside">-12.5</temperature>
<seats>
<seat location="front">
<id>1</id>
<temperature>32.5</temperature>
<heating-is-on/>
</seat>
<seat location="back">
<id>2</id>
<temperature>23.5</temperature>
</seat>
</seats>
</sensor-system>
必需的 :
d) XSLT(25 分)编写一个 XSL 转换,接收给定的 XML 作为输入,并输出带有所有座位 ID 号的文本,其中相应座位的温度低于内部温度并且加热被关闭。给定 XML 的输出应如下所示: 关闭加热的冷座椅:2 (23.5) 第一个数字是座椅 ID,第二个是座椅温度。
我的回答请检查:
<xsl:output method="text"/>
<xsl:template match="/">
<xsl:for-each select="/sensor-system/seats/seat/temperature">
<xsl:if test="(temperature < /sesnsor-system/temperature[@location="inside"]) | not(/sensor-system/seats/seat/heating-is-on)" >
<xsl:value-of select="concat('cold seats with heating switched of : ' , '',/sensor-system/seats/seat/id,'(,/sensor-system/seats/seat/temperature,')')/>
</xsl:if>
</xsl:for-each>
</xsl:template>