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와 동일한 원리로 독자적인 Calcul eval 함수를 만들어야한다고 생각한다. 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