다음과 같은 .xml 데이터가 있습니다.
<Check>
<NotfoundUser>
<User>
<Forename>Jenny</Forename>
<Surname>Hollands</Surname>
<Birthday>30.01.1985</Birthday>
<Status>Employee</Status>
<City>Los Angeles</City>
</User>
<User>
<Forename>Michael</Forename>
<Surname>Williams</Surname>
<Birthday>30.12.1965</Birthday>
<Status>Retired</Status>
<City>New York</City>
</User>
</NotfoundUser>
</Check>
.xsl 데이터를 작성하여 테이블을 만들려고합니다.
<div class='div4'>
<table class='table4' style='font-size:12pt'>
<tr>
<th>Name</th>
<th>Birthday</th>
<th>Notice</th>
</tr>
<xsl:for-each select="/Check/NotfoundUser/*">
<tr>
<td><xsl:value-of select="./Forename"/> <xsl:text> </xsl:text> <xsl:value-of select="Surname"/></td>
<td><xsl:value-of select="./Birthday"/></td>
<td>
<xsl:call-template name="replacecity">
<xsl:with-param name="value" select="./City"/>
</xsl:call-template>
</td>
</tr>
</xsl:for-each>
</table>
</div>
<!-- template to replace -->
<xsl:template name="replacecity">
<xsl:param name="value"/>
<xsl:choose>
<xsl:when test="$value = 'New York'">
<xsl:text>Live in New York</xsl:text>
</xsl:when>
<xsl:when test="$value = 'Los Angeles'">
<xsl:text>Live in Los Angeles</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$value"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
이렇게 도시 위에 위첨자를 만들어야합니다.
If Status = Retired -> superscript is 1
If Status = Employee -> superscript is 2
그래서 새 템플릿 (예 :)을 만들고 template replacestatus
내부에 통합 replacecity
하려고 생각하고 있지만 방법을 모르겠습니다. 이것에 대해 저를 도와 주실 수 있습니까, 아니면 그것에 대해 더 나은 아이디어가 있습니까?
여기서 추가 템플릿을 호출해야하는 이유를 모르겠습니다. 간단하게 할 수없는 이유 :
XSLT 1.0
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html"/>
<xsl:template match="/Check">
<table border="1">
<tr>
<th>Name</th>
<th>Birthday</th>
<th>Notice</th>
</tr>
<xsl:for-each select="NotfoundUser/User">
<tr>
<td>
<xsl:value-of select="Forename"/>
<xsl:text> </xsl:text>
<xsl:value-of select="Surname"/>
</td>
<td>
<xsl:value-of select="Birthday"/>
</td>
<td>
<xsl:text>Lives in </xsl:text>
<xsl:value-of select="City"/>
<sup>
<xsl:choose>
<xsl:when test="Status='Retired'">1</xsl:when>
<xsl:when test="Status='Employee'">2</xsl:when>
</xsl:choose>
</sup>
</td>
</tr>
</xsl:for-each>
</table>
</xsl:template>
</xsl:stylesheet>
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다