Quote:
Originally Posted by XmisterIS
But what syntax do I use to select all the title elements that have an attribute named lang with a value that contains the substring 'eng'?
|
You would use
the contains function. Example:
document_1.xml
Code:
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="application/xml" href="document_1.xslt"?>
<document>
<title>Title 1</title>
<title lang="eng">Title 2</title>
<title lang="eng-US">Title 3</title>
<title lang="eng-Latn-US">Title 4</title>
</document>
document_1.xslt
Code:
<?xml version="1.0" encoding="UTF-8"?>
<stylesheet xmlns="http://www.w3.org/1999/XSL/Transform" xmlns:xslt="http://www.w3.org/1999/XSL/Transform" version="1.0">
<output media-type="application/xhtml+xml"/>
<template match="/">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Demo Document</title>
<style>
* { margin: 0; padding: 0; }
html { margin: 2em; }
h1 { font-size: 1em; }
ol { margin: 0.25em 0 1em; padding-left: 1em; }
</style>
</head>
<body>
<h1>English Titles</h1>
<ol>
<xslt:for-each select="child::document/child::title[contains(attribute::lang, 'eng')]">
<!-- child::document/child::title[contains(attribute::lang, 'eng')] = document/title[contains(@lang, 'eng')] -->
<li><xslt:value-of select="self::node()"/></li>
</xslt:for-each>
</ol>
</body>
</html>
</template>
</stylesheet>