XML 변환에서 html 테이블로 올바른 출력을 생성하는 데 문제가 있습니다.
입력 XML :
<Report>
<Report>
<objective objective="Y1">
<function function="X1" />
<function function="X3" />
<function function="X4" />
<function function="X2" />
<function function="X6" />
</objective>
<objective objective="Y2" />
<objective objective="Y3" />
<objective objective="Y4">
<function function="X5" />
<function function="X3" />
</objective>
<objective objective="Y5">
<function function="X2" />
<function function="X1" />
<function function="X4" />
</objective>
</Report>
</Report>
원하는 출력 :
이것이 제가 지금까지 가지고있는 것입니다. 내 XSLT 2.0 :
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions">
<xsl:template match ="Report/Report" >
<html>
<head>
<title></title>
</head>
<body>
<table>
<tbody>
<tr>
<th>Objective\Function</th>
<xsl:for-each-group select="objective/function" group-by="@function">
<xsl:sort select="current-grouping-key()"/>
<th><xsl:value-of select="current-grouping-key()"/></th>
</xsl:for-each-group>
</tr>
<xsl:variable name="allData" select="objective"/>
<xsl:for-each select="objective">
<tr>
<td><xsl:value-of select="@objective"></xsl:value-of></td>
<xsl:for-each-group select="$allData" group-by="function/@function">
<xsl:sort select="current-grouping-key()"/>
<td><xsl:value-of select="count(current-grouping-key())"/></td>
</xsl:for-each-group>
</tr>
</xsl:for-each>
</tbody>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
나는 내가 오히려 가깝다고 생각한다. 나는 count 함수로 무언가를해야한다고 생각한다.
기본적으로 내가 원하는 것은 :
함수 노드에 속한 @function이 부모의 속성 @objective와 관련이 있다면 1 (발생 횟수에 따라 다름)을 세고 그렇지 않으면 0을 세십시오. 사전에 감사드립니다. 지난 며칠 동안 고군분투 해 왔습니다.
목표 요소에 대한 현재 xsl : for-each 루프 내 에서 현재 요소에 대한 참조를 보유 할 변수를 정의 할 수 있습니다.
<xsl:for-each select="objective">
<xsl:variable name="current" select="." />
그런 다음 함수 요소를 반복 하는 두 번째 xsl : for-each-group 내 에서 그룹화 키와 일치하는 현재 목표 (변수에 보관 됨) 내의 함수 요소 수를 간단히 계산할 수 있습니다 (그러면 0 또는 1)
<xsl:value-of select="count($current[function/@function=current-grouping-key()])"/>
이 XSLT 시도
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions"
exclude-result-prefixes="xs fn">
<xsl:template match ="Report/Report" >
<html>
<head>
<title></title>
</head>
<body>
<table>
<tbody>
<tr>
<th>Objective\Function</th>
<xsl:for-each-group select="objective/function" group-by="@function">
<xsl:sort select="current-grouping-key()"/>
<th><xsl:value-of select="current-grouping-key()"/></th>
</xsl:for-each-group>
</tr>
<xsl:variable name="allData" select="objective"/>
<xsl:for-each select="objective">
<xsl:variable name="current" select="." />
<tr>
<td><xsl:value-of select="@objective"></xsl:value-of></td>
<xsl:for-each-group select="$allData" group-by="function/@function">
<xsl:sort select="current-grouping-key()"/>
<td><xsl:value-of select="count($current[function/@function=current-grouping-key()])"/></td>
</xsl:for-each-group>
</tr>
</xsl:for-each>
</tbody>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
다음과 같은 출력이 생성됩니다.
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
</head>
<body>
<table>
<tbody>
<tr>
<th>Objective\Function</th>
<th>X1</th>
<th>X2</th>
<th>X3</th>
<th>X4</th>
<th>X5</th>
<th>X6</th>
</tr>
<tr>
<td>Y1</td>
<td>1</td>
<td>1</td>
<td>1</td>
<td>1</td>
<td>0</td>
<td>1</td>
</tr>
<tr>
<td>Y2</td>
<td>0</td>
<td>0</td>
<td>0</td>
<td>0</td>
<td>0</td>
<td>0</td>
</tr>
<tr>
<td>Y3</td>
<td>0</td>
<td>0</td>
<td>0</td>
<td>0</td>
<td>0</td>
<td>0</td>
</tr>
<tr>
<td>Y4</td>
<td>0</td>
<td>0</td>
<td>1</td>
<td>0</td>
<td>1</td>
<td>0</td>
</tr>
<tr>
<td>Y5</td>
<td>1</td>
<td>1</td>
<td>0</td>
<td>1</td>
<td>0</td>
<td>0</td>
</tr>
</tbody>
</table>
</body>
</html>
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다