xmlファイルの表示と評価にxslファイルを使用したいと考えています。 XMLファイルには、タイトル、説明、イメージ、および金額のある部品が含まれています。しかし、この金額は、XSLファイルで宣言するいくつかの変数に依存します。しかし、この場合は、XSLファイルのXML内から式を計算する必要があります。これには道がありますか?変数付きのXSL評価属性
例を参照してください:(@amountの式は、XMLからの変数を評価する必要があります)
XML:
<partslist>
<part value="1" amount="$variable1" visible="true">
<title>
<nl>Onderdeel 1</nl>
<fr>Partie 1</fr>
<en>Part 1</en>
<de>Teil 1</de>
</title>
<image src="images/partslist/part1.jpg"/>
</part>
<part value="2" amount="$variable1 * $variable2" visible="true">
<title>
<nl>Onderdeel 2</nl>
<fr>Partie 2</fr>
<en>Part 2</en>
<de>Teil 2</de>
</title>
<image src="images/partslist/part2.jpg"/>
</part>
<part value="3" amount="$variable3" visible="true">
<title>
<nl>Onderdeel 3</nl>
<fr>Partie 3</fr>
<en>Part 3</en>
<de>Teil 3</de>
</title>
<image src="images/partslist/part3.jpg"/>
</part>
<part value="4" amount="$variable1 + $variable3" visible="true">
<title>
<nl>Onderdeel 4</nl>
<fr>Partie 4</fr>
<en>Part 4</en>
<de>Teil 4</de>
</title>
<image src="images/partslist/part4.jpg"/>
</part>
</partslist>
XSL:事前
で<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
<xsl:template match="/">
<html>
<head>
<link rel="stylesheet" href="style.css" type="text/css"/>
</head>
<body>
<xsl:variable name="variable1" select="1" />
<xsl:variable name="variable2" select="2" />
<xsl:variable name="variable3" select="3" />
<div class="np">
<H2>Parts List</H2>
<table border ="1">
<tr>
<th style="width:15%;">ID</th>
<th style="width:15%;">Amount</th>
<th style="width:40%;">Description</th>
<th style="width:30%;">Image</th>
</tr>
<xsl:for-each select="partslist/part">
<tr>
<td><xsl:value-of select="@value" /></td>
<td><xsl:value-of select="@amount"/></td>
<td><xsl:value-of select="title/nl"/></td>
<td><img style="width:100%;" src="{image/@src}"/></td>
</tr>
</xsl:for-each>
</table>
</div>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
感謝を
あなたの試行が動作していない場所を正確にそれを明確にすることができますしてください? – Spangen
私は、xpath evalのDimitre answerと同じ原則であなた自身の計算評価関数を作成しなければならないと思う:https://stackoverflow.com/questions/7321553/xslt-interpret-a-text-nodes-value-as- xpath-query-and-it-in-transformati#7328577 – GGO
@Spangen 'amount'列に結果がXML内の式の評価式になるようにしたいが、それは動作していない。たとえば、最初の列は 'value = 1、amount = 1(variable1 = 1であるため)、title = Onderdeel1、image) – Pecoris