[완료] XSLT 질문입니다.
다음 코드는 원하는 대로 동작합니다.
<xsl:template match="list[@type!='definition']/li">
<li><xsl:apply-templates mode="li" /></li>
</xsl:template>
<xsl:template match="list[@type='definition']/li[@istitle='true']">
<dt><xsl:apply-templates mode="li" /></dt>
</xsl:template>
<xsl:template match="list[@type='definition']/li[@istitle='false']">
<dd><xsl:apply-templates mode="li" /></dd>
</xsl:template>
<xsl:template name="li">
<xsl:if test="@id">
<a><xsl:attribute name="name"><xsl:value-of select="@id" /></xsl:attribute></a>
</xsl:if>
<xsl:value-of select="." />
</xsl:template>
하지만 다음 코드는 동작하지 않습니다.
<xsl:template match="*[@name]/link">
<xsl:apply-templates mode="link" /><br />
</xsl:template>
<xsl:template match="list[@type!='definition']/link">
<li><xsl:apply-templates mode="link" /></li>
</xsl:template>
<xsl:template match="list[@type='definition']/link[@istitle='true']">
<dt><xsl:apply-templates mode="link" /></dt>
</xsl:template>
<xsl:template match="list[@type='definition']/link[@istitle='false']">
<dd><xsl:apply-templates mode="link" /></dd>
</xsl:template>
<xsl:template match="p/list">
<xsl:apply-templates mode="link" />
</xsl:template>
<xsl:template name="link">
<xsl:if test="@id">
<a><xsl:attribute name="name"><xsl:value-of select="@id" /></xsl:attribute></a>
</xsl:if>
<a>
<xsl:attribute name="href"><xsl:value-of select="@href" /></xsl:attribute>
<xsl:value-of select="." />
</a>
</xsl:template>
왜 그럴까요?
xsl:apply-templates의
xsl:apply-templates의 mode를 썼으면, xsl:template 에서도 같은 mode를 써줘야 불러온답니다. 그냥 불러오려면 select를 쓰면 될겁니다
If an xsl:apply-templates element has a mode attribute, then it applies only to those template rules from xsl:template elements that have a mode attribute with the same value; if an xsl:apply-templates element does not have a mode attribute, then it applies only to those template rules from xsl:template elements that do not have a mode attribute.
http://www.w3.org/TR/xslt#modes
을 사용해
을 사용해 해결했습니다. 인터넷으로 대충 배우다 보니 꼼꼼하지 못했군요. 감사합니다 ^^
> What is the difference between software and hard water?
} Bugs drown in hard water, but live forever in software.
Real programmers /* don't */ comment their code.
If it was hard to write, it should be /* hard to */ read.
댓글 달기