I built an XML workflow to create a rich HTML document with automatic hyperlinks and anchors using unique ids. But I need to add unique anchors to an existing element that are untagged. I don’t want to go through the hundreds of elements to tag the content, so I am wondering if there is a way to pull out the letter starting a paragraph and then append it to a section number to create the unique ID anchor attribute.
The XML looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<RULES>
<RULE>
<RULE_SECTION>
<RULE_subhead><num>3-3</num>. DOUBT AS TO PROCEDURE </RULE_subhead>
<rule_letterhead>a. Procedure </rule_letterhead>
<rule_letterhead-B>b. Determination of Score for Hole </rule_letterhead-B>
</RULE_SECTION>
<RULE_SECTION>
<RULE_subhead><num>4-1</num>. FORM AND MAKE OF CLUBS </RULE_subhead>
<rule_letterhead>a. General </rule_letterhead>
<rule_letterhead-B>b. Wear and Alteration </rule_letterhead-B>
<rule_letterhead-B>c. Damage in Normal Course of Play </rule_letterhead-B>
</RULE_SECTION>
</RULE>
</RULES>
Note how the two <rule_letterhead> and <rule_letterhead-B> elements start with an initial letter and period (a. b. c., etc). I’d like to build HTML to look like this:
<body>
<h2 class="RULE_subhead" id="r3-3">3-3. DOUBT AS TO PROCEDURE </h2>
<h3 class="rule_letterhead" id="r3-3a">a. Procedure </h3>
<h3 class="rule_letterhead" id="r3-3b">b. Determination of Score for Hole </h3>
<h2 class="RULE_subhead" id="r4-1">4-1. FORM AND MAKE OF CLUBS </h2>
<h3 class="rule_letterhead" id="r4-1a">a. General </h3>
<h3 class="rule_letterhead" id="r4-1b">b. Wear and Alteration </h3>
<h3 class="rule_letterhead" id="r4-1c">c. Damage in Normal Course of Play </h3>
</body>
So, the XSL has to pull the Section number and append it to the first letter of the elements <letterhead> or <letterhead-B> like this “4-1a”.
Here is the XSL I am currently using:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" encoding="UTF-8" doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"/>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>Untitled Document</title>
</head>
<body>
<xsl:apply-templates select="RULES"/>
</body>
</html>
</xsl:template>
<xsl:template match="RULE_subhead">
<h2 class="RULE_subhead" id="{concat('r',translate(normalize-space(num), ' ', ''))}">
<xsl:apply-templates/></h2>
</xsl:template>
<xsl:template match="rule_letterhead">
<h3 class="rule_letterhead"><xsl:apply-templates/></h3>
</xsl:template>
<xsl:template match="rule_letterhead-B">
<h3 class="rule_letterhead"><xsl:apply-templates/></h3>
</xsl:template>
</xsl:stylesheet>
It is working for all the other elements.
Thanks
1 Answer