Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can you grab each NMTOKEN in a set of NMTOKENS

Status
Not open for further replies.

mountainbiker

Programmer
Aug 21, 2002
122
GB
A DTD like

<!ELEMENT surgery (mark)>
<!ELEMENT human EMPTY>
<!ATTLIST human
bodyparts NMTOKENS #IMPLIED
>

A XML like
<surgery>
<human bodyparts=&quot;arm leg head&quot; />
</surgery>

How can I grab &quot;arm&quot;, &quot;leg&quot; and &quot;head&quot; for use in my XSLT? I don't have the option of changing the DTD :(

 
CAN THIS BE IMPROVED ON?

============================
<?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?>
<?xml-stylesheet type=&quot;text/xsl&quot; href=&quot;C:\Program Files\Altova\XML Spy Suite\Examples\nmtokens.xsl&quot;?>

<surgery>
<!-- should not pad with more than a single space between tokens and no leading or trailing spaces -->
<human bodyparts=&quot;arm leg head&quot;/>
</surgery>
============================
<?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?>
<xsl:stylesheet version=&quot;1.0&quot;
xmlns:xsl=&quot; <xsl:eek:utput method=&quot;xml&quot; version=&quot;1.0&quot; encoding=&quot;ISO-8859-1&quot; omit-xml-declaration=&quot;no&quot; indent=&quot;no&quot; media-type=&quot;text/html&quot;/>

<xsl:template name=&quot;each_nmtoken&quot;>
<xsl:param name=&quot;nmtokens&quot;/>
[<xsl:value-of select=&quot;substring-before($nmtokens, ' ')&quot;/>]<br/>
<xsl:if test=&quot;string-length($nmtokens) > 0&quot;>
<!-- remainder of string is [<xsl:value-of select=&quot;substring-after($nmtokens, ' ')&quot;/>]<br/> -->

<xsl:choose>
<xsl:when test=&quot;substring-after(substring-after($nmtokens, ' '), ' ') != ''&quot;>
<xsl:call-template name=&quot;each_nmtoken&quot;>
<xsl:with-param name=&quot;nmtokens&quot; select=&quot;substring-after($nmtokens, ' ')&quot;/>
</xsl:call-template>
</xsl:when>

<xsl:eek:therwise>
[<xsl:value-of select=&quot;substring-after($nmtokens, ' ')&quot;/>]<br/>
</xsl:eek:therwise>
</xsl:choose>
</xsl:if>
</xsl:template>


<xsl:template match=&quot;/&quot;>
<html>
<head>
<title>
test
</title>
</head>
<body>
<h2>
<xsl:call-template name=&quot;each_nmtoken&quot;>
<xsl:with-param name=&quot;nmtokens&quot; select=&quot;//surgery/human/@bodyparts&quot;/>
</xsl:call-template>

</h2>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
============================
 
I used the extension from
--- the xml source ---
<?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?>
<?xml-stylesheet type=&quot;text/xsl&quot; href=&quot;C:\Program Files\Altova\XML Spy Suite\Examples\nmtokens2.xsl&quot;?>

<surgery>
<!-- should not pad with more than a single space between tokens and no leading or trailing spaces -->
<human bodyparts=&quot;arm leg head&quot;/>
</surgery>


--- the stylesheet ---
<?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?>
<xsl:stylesheet version=&quot;1.0&quot;
xmlns:xsl=&quot; xmlns:str=&quot; extension-element-prefixes=&quot;str&quot;>

<xsl:import href=&quot;str.tokenize.template.xsl&quot; />

<xsl:eek:utput method=&quot;xml&quot; version=&quot;1.0&quot; encoding=&quot;ISO-8859-1&quot; omit-xml-declaration=&quot;no&quot; indent=&quot;yes&quot; media-type=&quot;text/html&quot;/>

<xsl:template match=&quot;/&quot;>
<html>
<head>
<title>
test
</title>
</head>
<body>
<h2>
<xsl:call-template name=&quot;str:tokenize&quot;>
<xsl:with-param name=&quot;string&quot; select=&quot;//surgery/human/@bodyparts&quot; />
<xsl:with-param name=&quot;delimiters&quot; select=&quot;string(' ')&quot; />
</xsl:call-template>
</h2>
</body>
</html>
</xsl:template>

</xsl:stylesheet>


--- output ---
<?xml version=&quot;1.0&quot; encoding=&quot;ISO-8859-1&quot;?>
<html>
<head>
<title>
test
</title>
</head>
<body>
<h2>
<token>arm</token>
<token>leg</token>
<token>head</token>
</h2>
</body>
</html>


--- QUESTION ---
rather than outputting the token as <token> elements, i would like to do some additional processing based on each token value. for example, if token = arm then print the html statement

<h2>the patient has had surgery on their arm<h2>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top