입력 XML과 같은 것입니다 문자열 길이를 사용하여 속성 값을 찾아XSLT - 정규 표현식 및
<link idref="c001_r1" target="page">1</link>
<link idref="r164">2004</link>
<link idref="ref1">Austen et al. 1975</link>
출력이 있어야
<link idref="c001_r1" target="literature"><sup>1</sup></link>
<link idref="r164" target="literature">2004</link>
<link idref="ref1" target="literature">Austen et al. 1975</link>
우리는 아래와 같이 XSLT를 썼다.
<xsl:template match="link">
<xsl:choose>
<xsl:when test="starts-with(@idref, 'r') and string-length(.) = 4">
<xsl:copy>
<xsl:apply-templates select="@*"/>
<xsl:attribute name="target">
<xsl:value-of select="'literature'" />
</xsl:attribute>
<xsl:apply-templates select="node()"/>
</xsl:copy>
</xsl:when>
<xsl:when test="starts-with(@idref, 'ref') and string-length(.) > 4">
<xsl:copy>
<xsl:apply-templates select="@*"/>
<xsl:attribute name="target">
<xsl:value-of select="'literature'" />
</xsl:attribute>
<xsl:apply-templates select="node()"/>
</xsl:copy>
</xsl:when>
<xsl:when test="contains(@idref, '(.+)_r')">
<xsl:copy>
<xsl:apply-templates select="@*"/>
<xsl:attribute name="target">
<xsl:value-of select="'literature'" />
</xsl:attribute>
<sup>
<xsl:apply-templates select="node()"/></sup>
</xsl:copy>
</xsl:when>
<xsl:when test="starts-with(@idref, 'ref') and string-length(.) < 3">
<xsl:copy>
<xsl:apply-templates select="@*"/>
<xsl:attribute name="target">
<xsl:value-of select="'literature'" />
</xsl:attribute>
<sup>
<xsl:apply-templates select="node()"/>
</sup>
</xsl:copy>
</xsl:when>
<xsl:otherwise>
<xsl:copy>
<xsl:apply-templates select="@*"/>
<xsl:attribute name="target"><xsl:text>page</xsl:text>
</xsl:attribute>
<xsl:apply-templates select="node()"/>
</xsl:copy>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
위의 xslt, 3 및 4 조건을 사용하는 동안 작동하지 않습니다. 속성 값과 문자열 길이에 따라 속성을 추가해야합니다. 스팅 길이를 계산하기 위해 (<) 부호를 언급 할 수 없습니다.
더 많은 설명이 포함 된 귀중한 답변을 주셔서 감사합니다. 정말 도움이됩니다. – Sumathi