|
498 | 498 | </xsl:choose>
|
499 | 499 | </xsl:template>
|
500 | 500 |
|
| 501 | +<!-- Utility template for processing @href attributes on <a> elements --> |
| 502 | +<!-- For XREFs, grab either the text content after the last # sign, or all the content if there is no # sign --> |
| 503 | +<!-- For non-XREFs, don't touch at all --> |
| 504 | +<xsl:template name="calculate-output-href"> |
| 505 | + <xsl:param name="source-href-value" select="@href"/> |
| 506 | + <xsl:param name="href-is-xref"/> |
| 507 | + |
| 508 | + <xsl:variable name="is-xref"> |
| 509 | + <xsl:choose> |
| 510 | + <xsl:when test="($href-is-xref = 0) or ($href-is-xref = 1)"> |
| 511 | + <xsl:value-of select="$href-is-xref"/> |
| 512 | + </xsl:when> |
| 513 | + <xsl:otherwise> |
| 514 | + <xsl:call-template name="href-is-xref"> |
| 515 | + <xsl:with-param name="href-value" select="$source-href-value"/> |
| 516 | + </xsl:call-template> |
| 517 | + </xsl:otherwise> |
| 518 | + </xsl:choose> |
| 519 | + </xsl:variable> |
| 520 | + |
| 521 | + <xsl:choose> |
| 522 | + <xsl:when test="$is-xref = 1"> |
| 523 | + <xsl:choose> |
| 524 | + <!-- If there is more than one # sign in content, recursively call template to get content after first # --> |
| 525 | + <xsl:when test="contains(substring-after($source-href-value, '#'), '#')"> |
| 526 | + <xsl:call-template name="calculate-output-href"> |
| 527 | + <xsl:with-param name="source-href-value" select="substring-after($source-href-value, '#')"/> |
| 528 | + <xsl:with-param name="href-is-xref" select="1"/> |
| 529 | + </xsl:call-template> |
| 530 | + </xsl:when> |
| 531 | + <!-- If there is a # sign in content, grab the # and all content thereafter --> |
| 532 | + <xsl:when test="contains($source-href-value, '#')"> |
| 533 | + <xsl:value-of select="concat('#', substring-after($source-href-value, '#'))"/> |
| 534 | + </xsl:when> |
| 535 | + <!-- Otherwise, just use all the text as is--> |
| 536 | + <xsl:otherwise> |
| 537 | + <xsl:value-of select="$source-href-value"/> |
| 538 | + </xsl:otherwise> |
| 539 | + </xsl:choose> |
| 540 | + </xsl:when> |
| 541 | + <xsl:otherwise> |
| 542 | + <!-- Just use the text as is --> |
| 543 | + <xsl:value-of select="$source-href-value"/> |
| 544 | + </xsl:otherwise> |
| 545 | + </xsl:choose> |
| 546 | +</xsl:template> |
| 547 | + |
501 | 548 | </xsl:stylesheet>
|
0 commit comments