XSLT formatting HTML Input - html

I am looking to use an XSLT to strip attributes out of an HTML file. The HTML file looks like this:
<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type" />
<title>CB Comfy Bike</title>
<meta name="atg:string,index:$repositoryId" content="prod10005" />
<meta name="atg:date:creationDate" content="955050507" />
<meta name="atg:date:startDate" content="978325200" />
<meta name="atg:date:endDate" content="1009861200" />
<meta name="atg:string:$url"
content="atgrep:/ProductCatalog/frame-product/prod10005?locale=en_US" />
<meta name="atg:string,index:$baseUrl"
content="atgrep:/ProductCatalog/frame-product/prod10005" />
<meta name="atg:string:$repository.repositoryName" content="ProductCatalog" />
<meta name="atg:string:$itemDescriptor.itemDescriptorName" content="frame-product" />
<meta name="atg:string:childSKUs.$repositoryId" content="sku20007" />
<meta name="atg:string:childSKUs.$itemDescriptor.itemDescriptorName" content="bike-sku" />
<meta name="atg:date:childSKUs.creationDate" content="955068027" />
<meta name="atg:float:childSKUs.listPrice" content="400.0" />
<meta name="atg:float:childSKUs.salePrice" content="300.0" />
<meta name="atg:boolean:childSKUs.onSale" content="false" />
<meta name="atg:string:parentCategory.$repositoryId" content="cat55551" />
<meta name="atg:date:parentCategory.creationDate" content="956950321" />
<meta name="atg:string,docset:ancestorCategories.$repositoryId" content="cat10002" />
<meta name="atg:string,docset:ancestorCategories.$repositoryId" content="cat10003" />
<meta name="atg:string,docset:ancestorCategories.$repositoryId" content="cat55551" />
</head>
<body>
<div class="atg:role:displayName" id="0"> CB Comfy Bike </div>
<div class="atg:role:longDescription" id="1"> This bike is just right, whether you are a
commuter or want to explore the fire roads. The plush front suspension will smooth out
the roughest bumps and the big disc brakes provide extra stopping power for those big
downhills. </div>
<div class="atg:role:keywords" id="2"> mountain_bike comfort_bike </div>
<div class="atg:role:childSKUs.displayName" id="3"> CB Comfy Bike Medium </div>
<div class="atg:role:childSKUs.listPrice" id="4"> 400.0 </div>
<div class="atg:role:childSKUs.description" id="5"> Medium </div>
<div class="atg:role:parentCategory.displayName" id="6"> Mountain Bikes </div>
</body>
</html>
I am looking to at a new tag for each div, I have not focused on naming convensions yet, as it is proof of concept. However im not sure how to differenciate between div tags. This XSLT I have got so far is:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="xml" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="#*|node()">
<xsl:copy>
<xsl:apply-templates select="#*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="head"/>
<xsl:template match="body">
<xsl:copy>
<xsl:value-of select="div/text()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
Which returns:
<?xml version="1.0" encoding="utf-8"?>
<html>
<body> CB Comfy Bike </body>
</html>
How would i turn the input into something like this
<?xml version="1.0" encoding="UTF-8"?>
<root>
<tag1>CB Comfy Bike</tag1>
<tag2>This bike is just right, whether you are a
commuter or want to explore the fire roads. The plush front suspension will smooth out
the roughest bumps and the big disc brakes provide extra stopping power for those big
downhills.</tag2>
<tag3>mountain_bike comfort_bike</tag3>
<tag4>CB Comfy Bike Medium</tag4>
<tag5>400.0</tag5>
<tag6>Medium</tag6>
<tag7>Mountain Bikes</tag7>
</root>
The trouble i have is differentiating between the Div tags.

This short and simple transformation:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:template match="/*">
<root>
<xsl:apply-templates select="body/div"/>
</root>
</xsl:template>
<xsl:template match="div">
<xsl:element name="tag{position()}">
<xsl:value-of select="."/>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
when applied on the provided XML document:
<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type" />
<title>CB Comfy Bike</title>
<meta name="atg:string,index:$repositoryId" content="prod10005" />
<meta name="atg:date:creationDate" content="955050507" />
<meta name="atg:date:startDate" content="978325200" />
<meta name="atg:date:endDate" content="1009861200" />
<meta name="atg:string:$url"
content="atgrep:/ProductCatalog/frame-product/prod10005?locale=en_US" />
<meta name="atg:string,index:$baseUrl"
content="atgrep:/ProductCatalog/frame-product/prod10005" />
<meta name="atg:string:$repository.repositoryName" content="ProductCatalog" />
<meta name="atg:string:$itemDescriptor.itemDescriptorName" content="frame-product" />
<meta name="atg:string:childSKUs.$repositoryId" content="sku20007" />
<meta name="atg:string:childSKUs.$itemDescriptor.itemDescriptorName" content="bike-sku" />
<meta name="atg:date:childSKUs.creationDate" content="955068027" />
<meta name="atg:float:childSKUs.listPrice" content="400.0" />
<meta name="atg:float:childSKUs.salePrice" content="300.0" />
<meta name="atg:boolean:childSKUs.onSale" content="false" />
<meta name="atg:string:parentCategory.$repositoryId" content="cat55551" />
<meta name="atg:date:parentCategory.creationDate" content="956950321" />
<meta name="atg:string,docset:ancestorCategories.$repositoryId" content="cat10002" />
<meta name="atg:string,docset:ancestorCategories.$repositoryId" content="cat10003" />
<meta name="atg:string,docset:ancestorCategories.$repositoryId" content="cat55551" />
</head>
<body>
<div class="atg:role:displayName" id="0"> CB Comfy Bike </div>
<div class="atg:role:longDescription" id="1"> This bike is just right, whether you are a
commuter or want to explore the fire roads. The plush front suspension will smooth out
the roughest bumps and the big disc brakes provide extra stopping power for those big
downhills. </div>
<div class="atg:role:keywords" id="2"> mountain_bike comfort_bike </div>
<div class="atg:role:childSKUs.displayName" id="3"> CB Comfy Bike Medium </div>
<div class="atg:role:childSKUs.listPrice" id="4"> 400.0 </div>
<div class="atg:role:childSKUs.description" id="5"> Medium </div>
<div class="atg:role:parentCategory.displayName" id="6"> Mountain Bikes </div>
</body>
</html>
produces the wanted, correct result:
<root>
<tag1> CB Comfy Bike </tag1>
<tag2> This bike is just right, whether you are a
commuter or want to explore the fire roads. The plush front suspension will smooth out
the roughest bumps and the big disc brakes provide extra stopping power for those big
downhills. </tag2>
<tag3> mountain_bike comfort_bike </tag3>
<tag4> CB Comfy Bike Medium </tag4>
<tag5> 400.0 </tag5>
<tag6> Medium </tag6>
<tag7> Mountain Bikes </tag7>
</root>
Explanation:
Appropriate use of templates.
Use of the position() function.
Use of AVT (Attribute Value Templates).

Almost desired output )
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="xml" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="#*|node()">
<xsl:copy>
<xsl:apply-templates select="#*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="head"/>
<xsl:template match="body">
<xsl:for-each select="div">
<xsl:element name="{concat('tag', position())}">
<xsl:value-of select="./text()"/>
</xsl:element>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>

I'd do something similar to Timur but I wouldn't use the for-each. I'd use a template to iterate over the div's within the body
Applying the following to the supplied XML
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="#*|node()">
<xsl:copy>
<xsl:apply-templates select="#*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="html">
<xsl:apply-templates select="body"/>
</xsl:template>
<xsl:template match="body">
<root>
<xsl:apply-templates select="div"/>
</root>
</xsl:template>
<xsl:template match="div">
<xsl:element name="{concat('tag', position())}">
<xsl:value-of select="."/>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
produces the desired output
<?xml version="1.0" encoding="UTF-8"?>
<root>
<tag1> CB Comfy Bike </tag1>
<tag2> This bike is just right, whether you are a
commuter or want to explore the fire roads. The plush front suspension will smooth out
the roughest bumps and the big disc brakes provide extra stopping power for those big
downhills. </tag2>
<tag3> mountain_bike comfort_bike </tag3>
<tag4> CB Comfy Bike Medium </tag4>
<tag5> 400.0 </tag5>
<tag6> Medium </tag6>
<tag7> Mountain Bikes </tag7>
</root>
Use of:
Identity transform
attribute value template
apply-templates to iterate over child nodes

Related

Merging two XML files while transforming them using XSL

I have two XML files which I want to transform into one HTML file using XSL.
I transform them using xsltproc first.xml transform.xsl > output.html command in Linux terminal. Values from first.xml work perfectly and transform into HTML but I cannot force second.xml to work as well. It just didn't appear in file. I know there were questions like this on StackOverflow but I still couldn't figure out what I am doing wrong. It seems like something is wrong with match = "document('effects.xml')/effects" but I don't know what exactly.
first.xml
<elements>
<listOfElements>
<element>
*some data*
</element>
<element>
*some data*
</element>
</listOfElements>
</elements>
second.xml
<effects>
<effect>
<name> NAME1 </name>
<cost> COST1 </cost>
</effect>
<effect>
<name> NAME2 </name>
<cost> COST2 </cost>
</effect>
<effect>
<name> NAME3 </name>
<cost> COST3 </cost>
</effect>
</effect>
transform.xsl
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes"/>
<xsl:template match="/">
<xsl:text disable-output-escaping='yes'><!DOCTYPE html></xsl:text>
<html>
<head>
<meta charset="UTF-8"/>
<link rel="stylesheet" type="text/css" href="styl.css"/>
</head>
<body>
<xsl:apply-templates select="elements"/>
<xsl:apply-templates select="effects"/>
</body>
</html>
</xsl:template>
<xsl:template match="elements">
<div>
THIS WORKS
</div>
</xsl:template>
<xsl:template match="document('effects.xml')/effects">
<div>
<xsl:for-each select="effects/effect">
<div>
<p><xsl:value-of select="name"/></p>
</div>
</xsl:for-each>
</div>
</xsl:template>
Use <xsl:apply-templates select="document('effects.xml')/effects"/> and then in the match="effects" and <xsl:for-each select="effect">.

for-each-group text paragraph - xslt 2.0

I am looking for a solution to group text based on the title h1. I tried this with for-each-group, starts-with ="h1". The problem is that the h1 is not on the same level as the rest of the elements (div/h1).
Input html:
<!DOCTYPE html SYSTEM "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>test</title>
</head>
<body>
<div>
<h1><b>TRAIN</b></h1>
</div>
<p>text</p>
<p>In this field there is text</p>
<div>
<h1><b>nr1</b><b>CAR</b></h1>
</div>
<h2><b>1.</b><b>nr2</b><b>area</b></h2>
<p>infos about cars</p>
<p><b>more and</b>more infos about cars</p>
</body>
</html>
What I have so far is:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"
xpath-default-namespace="http://www.w3.org/1999/xhtml">
<xsl:output omit-xml-declaration="yes" method="xhtml" version="1.0" encoding="UTF-8"
indent="yes"/>
<xsl:template match="head"/>
<xsl:template match="body">
<xsl:for-each-group select = "*" group-starting-with = "h1">
<output>
<xsl:apply-templates select="current-group()"/>
</output>
</xsl:for-each-group>
</xsl:template>
<xsl:template match="*">
<xsl:element name="{name()}">
<xsl:apply-templates select="node()"/>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
But the output is not working the way I want. I would like to have two output-blocks as this example output:
<html>
<output>
<div><h1><b>TRAIN</b></h1></div>
<p>text</p>
<p>In this field there is text</p>
</output>
<output>
<div><h1><b>nr1</b><b>CAR</b></h1></div>
<h2>
<b>1.</b>
<b>nr2</b>
<b>area</b>
</h2>
<p>infos about cars</p>
<p><b>more and</b>more infos about cars</p>
</output>
Thanks for any help!
You could use the descendant-or-self axis, to group starting on elements which have h1 as a descendant (or are h1 elements themselves)
<xsl:for-each-group select="*" group-starting-with="*[descendant-or-self::h1]">
Also note that in your XSLT you have used xpath-default-namespace, but your input XML does not use that namespace, so as it stands your body template in your XSLT won't match the input. Either you need to add the default namespace to your input, or remove the xpath-default-namespace from your XSLT.
How about:
XSLT 2.0
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="utf-8" indent="yes"/>
<xsl:template match="/html">
<xsl:copy>
<xsl:for-each-group select="body/*" group-starting-with="div[h1]">
<output>
<xsl:copy-of select="current-group()"/>
</output>
</xsl:for-each-group>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>

Dynamically change value of in an XSL file

Currently the displaying the XML in a browser along with the XSL data is correct except for one thing. In some colleges I have one department while in orders I have more than one (up to 9). How I can dynamically output the data based on the number of department for each college? Currently it only outputs one department per college.
College.xml File
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?xml-stylesheet type="text/xsl" href="colleges.xsl"?><colleges>
<college id="0">
<school>College of Education</school>
<mission>text</mission>
<department id="0">Educational Psychology and Leadership</department>
<department id="1">Health and Human Performance</department>
<department id="2">Language, Literacy and Intercultural Studies</department>
<department id="3">Teaching, Learning and Innovation</department>
</college>
<college id="1">
<school>College of Nursing</school>
<mission>text</mission>
<department id="0">Nursing</department>
</college>
<college id="2">
<school>School of Business</school>
<mission>text</mission>
<department id="0">Accounting and Management Information Systems</department>
<department id="1">Applied Business Technology</department>
</college></colleges>
College.xsl file:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body style="font-family:Arial;font-size:12pt;background-color:#EEEEEE">
<xsl:for-each select="colleges/college">
<div style="background-color:teal;color:white;padding:4px">
<span style="font-weight:bold"><xsl:value-of select="school"/></span> - <br /><xsl:value-of select="mission"/>
</div>
<div style="margin-left:20px;margin-bottom:1em;font-size:10pt">
<p>
<xsl:value-of select="department"/><br />
</p>
</div>
</xsl:for-each>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Try:
<xsl:template match="/"> ...
<xsl:for-each select="colleges/college">
...
<xsl:apply-templates select="department"/>
...
</xsl:for-each>
</xsl:template>
<xsl:template match="department">... what you want for each department</xsl:template>
Give this a shot...
<xsl:template match="/">
<html>
<body style="font-family:Arial;font-size:12pt;background-color:#EEEEEE">
<xsl:for-each select="colleges/college">
<div style="background-color:teal;color:white;padding:4px">
<span style="font-weight:bold"><xsl:value-of select="school"/></span> - <br /><xsl:value-of select="mission"/>
</div>
<div style="margin-left:20px;margin-bottom:1em;font-size:10pt">
<p>
<xsl:apply-templates select="department"/>
</p>
</div>
</xsl:for-each>
</body>
</html>
</xsl:template>
<xsl:template match="department">
<xsl:value-of select="."/><br />
</xsl:template>

How to convert all "LF" chars to "<br />" tag and show it on the HTML page

How to convert all LF chars to <br /> tags and show it on the HTML page?
I have the following example XML file:
<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="data.xslt"?>
<data>
<lines>
Line 1
Line 2
Line 3
Line 4
Line 5
Line 6
</lines>
</data>
and I want to show all lines on the HTML page. For this I use the following XSLT transformation:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" version="1.0" encoding="utf-8" indent="yes"/>
<xsl:template match="/">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
</head>
<body>
<xsl:variable name="filtered">
<xsl:call-template name="replace">
<xsl:with-param name="string" select="./data/lines"/>
<xsl:with-param name="search" select="'
'"/>
<xsl:with-param name="new"><br /></xsl:with-param>
</xsl:call-template>
</xsl:variable>
<td align="left">
<xsl:value-of select="$filtered" disable-output-escaping="yes"/>
</td>
</body>
</html>
</xsl:template>
<xsl:template name="replace">
<xsl:param name="string"/>
<xsl:param name="search"/>
<xsl:param name="new"/>
<xsl:choose>
<xsl:when test="contains($string, $search)">
<xsl:value-of select="substring-before($string, $search)"/>
<xsl:value-of select="$new"/>
<xsl:call-template name="replace">
<xsl:with-param name="string" select="substring-after($string, $search)"/>
<xsl:with-param name="search" select="$search"/>
<xsl:with-param name="new" select="$new"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$string"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
When I open that XML file in Firefox (I use browser to show XSLT transformation) I will see that result:
Line 1Line 2Line 3Line 4Line 5Line 6
As you see, LF chars were not replaced by <br /> tags.
But when I use other string, for example EOL:
<xsl:with-param name="new">EOL</xsl:with-param>
I will see expected result:
EOLLine 1EOLLine 2EOLLine 3EOLLine 4EOLLine 5EOLLine 6EOL
The problem is with the convert/display <br /> tag.
You can pass a node fragment as a parameter value, as you do with <xsl:with-param name="new"><br /></xsl:with-param>, but to output that as a br element in your template you need to use <xsl:copy-of select="$new"/>, not xsl:value-of.
[edit] Here is an example: http://home.arcor.de/martin.honnen/xslt/test2012062801.xml. The stylesheet is at http://home.arcor.de/martin.honnen/xslt/test2012062801.xsl, I will also include it below:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" version="4.01" encoding="utf-8" indent="yes"/>
<xsl:template match="/">
<html>
<head>
<title>Example</title>
</head>
<body>
<xsl:variable name="filtered">
<xsl:call-template name="replace">
<xsl:with-param name="string" select="data/lines"/>
<xsl:with-param name="search" select="'
'"/>
<xsl:with-param name="new"><br /></xsl:with-param>
</xsl:call-template>
</xsl:variable>
<div>
<xsl:copy-of select="$filtered"/>
</div>
</body>
</html>
</xsl:template>
<xsl:template name="replace">
<xsl:param name="string"/>
<xsl:param name="search"/>
<xsl:param name="new"/>
<xsl:choose>
<xsl:when test="contains($string, $search)">
<xsl:value-of select="substring-before($string, $search)"/>
<xsl:copy-of select="$new"/>
<xsl:call-template name="replace">
<xsl:with-param name="string" select="substring-after($string, $search)"/>
<xsl:with-param name="search" select="$search"/>
<xsl:with-param name="new" select="$new"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$string"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
You have extra quotes in your parameter value. Try changing the line...
<xsl:with-param name="search" select="'
'"/>
To...
<xsl:with-param name="search" select="
"/>
UPDATE
As pointed out by the OP, the above is incorrect and will cause an XSLT transformation error.
I believe the answer by #banana to be the correct one.
IMHO, xsl:anaylze-string is the perfect fit for this problem. This XSLT 2.0 style-sheet run under Saxon ...
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fn="http://www.w3.org/2005/xpath-functions"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:so="http://stackoverflow.com/questions/11222334"
xmlns:x="http://www.w3.org/1999/xhtml"
xmlns="http://www.w3.org/1999/xhtml"
exclude-result-prefixes="xsl fn xs so x">
<xsl:output method="xhtml" encoding="utf-8" indent="yes"
doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN"
omit-xml-declaration="yes" />
<xsl:template match="/">
<html>
<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/></head>
<body>
<xsl:apply-templates select="data/lines"/>
</body>
</html>
</xsl:template>
<xsl:template match="lines">
<xsl:analyze-string select="." regex="\n">
<xsl:matching-substring>
<br />
<xsl:value-of select="'
'" />
</xsl:matching-substring>
<xsl:non-matching-substring>
<xsl:value-of select="."/>
</xsl:non-matching-substring>
</xsl:analyze-string>
</xsl:template>
</xsl:stylesheet>
... when applied to this input document ...
<?xml version="1.0" encoding="utf-8"?>
<data>
<lines>
Line 1
Line 2
Line 3
Line 4
Line 5
Line 6
</lines>
</data>
... will produce this html page ...
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "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" />
</head>
<body><br />
Line 1<br />
Line 2<br />
Line 3<br />
Line 4<br />
Line 5<br />
Line 6<br />
</body>
</html>
Try to replace:
<xsl:with-param name="new"><br /></xsl:with-param>
with:
<xsl:with-param name="new"><br /></xsl:with-param>
this will write current node value replacing \n with <br/>
<xsl:value-of select="replace(., '\n', '<br/>')"/>

Vertical output XSL and XML

I am working on a simple dictionary in XML, and now I'm trying to output some words vertical, but they all come out on a line without spaces.
This is some of the XML file
<thesaurus>
<dictionary>
<language>English</language>
<word type="1">word 1</word>
<word type="2">word 2</word>
<word type="3">word 3</word>
<word type="4">word 4</word>
<word type="5">word 5</word>
<word type="6">word 6</word>
</dictionary>
</thesaurus>
This is my first "almost" solution
<xsl:template match="/">
<html>
<body>
<xsl:apply-templates select="//word">
<xsl:sort order="ascending"/>
</xsl:apply-templates>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
That solution only prints out all the word like this
AgentsColorFoundationsGrainPartialPogotypePretendSilentStrollTender
My second try is something like this
<xsl:for-each select="thesaurus">
<h1> <xsl:value-of select="//word"/></h1>
</xsl:for-each>
In that way I could style the words and they will print vertical, but the thing is that only the first of the words is printing. =/
Would be great with a hint :)
Thanks
Use this template:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/">
<html>
<body>
<xsl:apply-templates select="*/*/word">
<xsl:sort order="ascending"/>
</xsl:apply-templates>
</body>
</html>
</xsl:template>
<xsl:template match="word">
<xsl:value-of select="."/>
<br/>
</xsl:template>
</xsl:stylesheet>
Output:
<html>
<body>word 1<br />word 2<br />word 3<br />word 4<br />word 5<br />word 6<br /></body>
</html>