Some of the values of my XML file are not displaying when transformed. Looks like something is not right witn XSL namespaces, but i can't figure it out.
XML file to transform
<?xml-stylesheet type="text/xsl" href="birth_new_3.xsl"?>
<ns2:ROGDINFResponse xmlns="urn://x-artefacts-zags-rogdinf/types/4.0.1"
xmlns:ns2="urn://x-artefacts-zags-rogdinf/root/112-51/4.0.1">
<ns2:ZgsAnswer>
<ns2:BrthReg>
<ns2:BrthLcs>
<SerLcs>II-LP</SerLcs>
<NumLcs>443334</NumLcs>
<DateLcs>1988-03-18</DateLcs>
</ns2:BrthLcs>
<ns2:SvReg>
<ns2:SvRodiv>
<ns2:FIOrogd>
<Last>Last</Last>
<First>Fname</First>
<Middle>Mname</Middle>
</ns2:FIOrogd>
<ns2:BirthDate>1988-01-19</ns2:BirthDate>
<ns2:BirthPlace Place="Some place"/>
</ns2:SvRodiv>
</ns2:SvReg>
</ns2:BrthReg>
</ns2:ZgsAnswer>
</ns2:ROGDINFResponse>
XSL file
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ns2="urn://x-artefacts-zags-rogdinf/root/112-51/4.0.1"
xmlns="urn://x-artefacts-zags-rogdinf/types/4.0.1">
<xsl:output method="html"/>
<xsl:template match="/">
<HTML>
<BODY>
<H2>Birth data</H2>
<span>Serial: <b>
<xsl:apply-templates select="//ns2:ROGDINFResponse/ns2:ZgsAnswer/ns2:BrthReg/ns2:BrthLcs/SerLcs"/>
</b>
</span>
<p>
<span>Number: <b>
<xsl:apply-templates select="//ns2:ROGDINFResponse/ns2:ZgsAnswer/ns2:BrthReg/ns2:BrthLcs/NumLcs"/>
</b>
</span>
</p>
<p>
<span>Date: <b>
<xsl:apply-templates select="//ns2:ROGDINFResponse/ns2:ZgsAnswer/ns2:BrthReg/ns2:BrthLcs/DateLcs"/>
</b>
</span>
</p>
<H3>Additional data: </H3>
<span>Last, First, Middle:
<b>
<xsl:apply-templates select="//ns2:ROGDINFResponse/ns2:ZgsAnswer/ns2:BrthReg/ns2:SvReg/ns2:SvRodiv/ns2:FIOrogd/Last"/>
</b>
<b>
<xsl:apply-templates select="//ns2:ROGDINFResponse/ns2:ZgsAnswer/ns2:BrthReg/ns2:SvReg/ns2:SvRodiv/ns2:FIOrogd/First"/>
</b>
<b>
<xsl:apply-templates select="//ns2:ROGDINFResponse/ns2:ZgsAnswer/ns2:BrthReg/ns2:SvReg/ns2:SvRodiv/ns2:FIOrogd/Middle"/>
</b>
</span>
<p>
<span>Date: <b>
<xsl:apply-templates select="//ns2:ROGDINFResponse/ns2:ZgsAnswer/ns2:BrthReg/ns2:SvReg/ns2:SvRodiv/ns2:BirthDate"/>
</b>
</span>
</p>
<p>
<span>Place: <b>
<xsl:apply-templates select="//ns2:ROGDINFResponse/ns2:ZgsAnswer/ns2:BrthReg/ns2:SvReg/ns2:SvRodiv/ns2:BirthPlace/#Place"/>
</b>
</span>
</p>
</BODY>
</HTML>
</xsl:template>
</xsl:stylesheet>
Some of the values of my XML are diplaying just fine, but values of the fields without namespaces are not diplaying (SerLcs, NumLcs, DateLcs, Last, First, Middle).
How can i fix my XSL?
Instead of xmlns="urn://x-artefacts-zags-rogdinf/types/4.0.1" in the XSLT you want xpath-default-namespace="urn://x-artefacts-zags-rogdinf/types/4.0.1" in there. Note that this only works with XSLT 2 and 3 processors like Saxon 9 or 10, Saxon-JS 2, XmlPrime, Exselt, AltovaXML.
First, Last, and Middle do have a namespace: they're in namespace urn://x-artefacts-zags-rogdinf/types/4.0.1. In XPath by default an unprefixed name refers to an element in no namespace. You can change this using xpath-default-namespace as #MartinHonnen suggests.
Related
I have a set of XML files where place names (in divergent historic spelling) are tagged as
<place>: cf. sample file. The place tag also contains the attribute link, whose value is a hyperlink to a World Historical Gazetteer page, e.g.:
<place name="Wien" type="place_of_issue"
link="http://whgazetteer.org/places/12346175/portal">Wien</place>
Converting the XML files to HTML with XSLT, I want every such tag in the text to be replaced by a hyperlink <a href>, linking to the same WHG URL.
A minimal version of my XSL based on Michael Hor-257k's answer is:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="html"/>
<xsl:template match="/">
<!-- Jekyll statement -->
---
<xsl:for-each select="source/metadata/digital_surrogate">
layout: page
title: <xsl:value-of select="#filename"/>
permalink: /<xsl:value-of select="#filename"/>/
exclude: true
---
</xsl:for-each>
<!-- Get transcription with links -->
<div class="flex-container">
<div><p><strong>Transkription:</strong></p>
<p><xsl:apply-templates select="//div">
</xsl:apply-templates>
<!-- include WHG links -->
<xsl:for-each select="//place">
<p>Genannte Orte im World Historical Gazetteer:</p>
<a href="{//place/#link}" target="_blank">
<xsl:value-of select="."/>
</a><br/>
</xsl:for-each>
</p><br/>
</div>
</div>
</xsl:template>
</xsl:stylesheet>
This at least correctly displays all place names mentioned in the correct order, with correct WHG links and correct names:
Wien
Maintz
Wien
However, the links still appear below the transcription, not within.
My desired HTML output would be:
<div class="flex-container">
<div>
<p><strong>Transkription:</strong></p>
<p>
Wir Vorsteher und gesamte
Meister des ehrsamen Handwerks der bürgerl:[ichen] Tischlern in der K:[aiserlich]
K:[öniglichen] Haubt = und Residenz Stadt Wien (beglaubigen) hiermit,
daß gegenwertiger Tischlergesell, Namens Georg
Gramer von Maintz - -
[etc.]
</p>
</div>
</div>
I am guessing that instead of:
<xsl:variable name="urlPlace">
<xsl:value-of select="#link"/>
</xsl:variable>
<xsl:apply-templates select="//place"/>
you want to do:
<a href="{#link}" target="_blank">
<xsl:value-of select="."/>
</a>
Untested, because no example to test with was provided.
--- added ---
See if you can use this as your starting point:
XSLT 1.0
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html"/>
<xsl:template match="/source">
<html>
<body>
<xsl:apply-templates select="content/body/div"/>
</body>
</html>
</xsl:template>
<xsl:template match="div">
<p>
<xsl:apply-templates select="text"/>
</p>
</xsl:template>
<xsl:template match="place">
<a href="{#link}" target="_blank">
<xsl:value-of select="."/>
</a>
</xsl:template>
</xsl:stylesheet>
To understand this and adapt it to your needs, you will need to study XSLT's processing model: https://www.w3.org/TR/1999/REC-xslt-19991116/#section-Processing-Model
If you want to transform a place element like <place name="Wien" type="place_of_issue" link="http://whgazetteer.org/places/12346175/portal">Wien</place> into an HTML a element use a template
<xsl:template match="place">
<a href="{#link}">
<xsl:value-of select="."/>
</a>
</xsl:template>
Write templates for the transformation of other elements like the ancestors of the places and make sure these templates process child nodes with <xsl:apply-templates/>.
That way the structure and order of the input should be preserved, only that you have HTML in the output reflecting the semantic XML elements you have in the input.
The two previous answers helped me understand the nesting rules in XSL that I wasn't familiar with.
So here is the full XSL that does exactly what I want:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="html"/>
<!-- BESCHREIBUNG, BILD UND TEXT AUF "SOURCE" EBENE -->
<xsl:template match="source">
<!-- Jekyll statement --> --- <xsl:for-each select="metadata/digital_surrogate">
layout: page title: <xsl:value-of select="#filename"/> permalink: /<xsl:value-of
select="#filename"/>/ exclude: true --- </xsl:for-each>
<!-- Metadaten -->
<xsl:for-each select="metadata/source_description">
<h3>Ausstellungsort: <xsl:value-of select="#place"/></h3>
<h3>Ausstellungsdatum: <xsl:value-of select="#date"/></h3>
</xsl:for-each>
<xsl:for-each select="edition">
<h4 align="center">ediert von: <xsl:value-of select="editors/#name"/></h4>
<h4 align="center">zuletzt bearbeitet: <xsl:value-of
select="transcription_info/#last_revision_date"/></h4>
</xsl:for-each>
<br/>
<xsl:for-each select="metadata/digital_surrogate">
<xsl:variable name="urlVar">
<xsl:value-of select="#URL"/>
</xsl:variable>
<img src="{$urlVar}" valign="top"/>
</xsl:for-each>
<!-- HTML-Flex-Container für Digitalisat und Inhalt -->
<div class="flex-container">
<div>
<p>
<strong>Graphische Elemente:</strong>
</p>
<p>
Art des Siegels: <xsl:value-of select="metadata/source_description/#seal"/>
Sonstiges: <xsl:for-each select="visual_element"/>
</p>
<br/>
</div>
</div>
<hr/>
<div class="flex-container">
<div>
<p>
<strong>Transkription:</strong>
</p>
<p>
<xsl:apply-templates select="content/body/div"/>
</p>
</div>
<div>
<p>
<strong>Übersetzung:</strong>
</p>
<p>
<xsl:apply-templates select="translation"/>
</p>
<br/>
</div>
</div>
</xsl:template>
<!-- WHG LINKS AUF EBENE DIV UND TEXT -->
<xsl:template match="div">
<p>
<xsl:apply-templates select="text"/>
</p>
</xsl:template>
<xsl:template match="place">
<a href="{#link}" target="_blank">
<xsl:value-of select="."/>
</a>
</xsl:template>
</xsl:stylesheet>
below is my XML which consist below nodes.
<richtext >
<par def="3">
paragraph value 1
<run>
<font style="underline" />run value 1
</run>.
paragraph value 2
<run>
<font style="underline" />run value 2
</run>
paragraph value 3
<run>
<font style="underline" />run value 2 <br /> run value on new line
</run>
paragraph value 4
</par>
</richtext>
i am transforming above xml to html using below xslt. i am new to xslt please help me.
<xsl:template match="/">
<div>
<xsl:apply-templates select="richtext" />
</div>
<xsl:template name="richtext">
<xsl:apply-templates select="par" />
<xsl:apply-templates select="table" />
<xsl:template match="par">
<p>
<xsl:if test="text()">
<xsl:value-of disable-output-escaping="yes" select="text()" />
<xsl:value-of disable-output-escaping="yes" select="*/following-sibling::text()" />
</xsl:if>
<xsl:if test="run">
<xsl:apply-templates select="run" />
<xsl:value-of disable-output-escaping="yes" select="run/following-sibling::text()" />
</xsl:if>
</p>
<xsl:template match="run">
<span>
<xsl:call-template name="style" />
<xsl:value-of disable-output-escaping="yes" select="current()" />
</span>
i want below html output
<p>
paragraph value 1
<span style="underline">
run value 1
</span>.
paragraph value 2
<span style="underline">
run value 2 <br /> run value on new line
</span>
paragraph value 3
<span style="underline">
run value 2
</span>
paragraph value 4
</p>
Please see updated HTML output. can you please tell me what to do ? i want to preserve style from xml.
Edit : if we add in XML then i want text after on new line in HTML.
It looks like you want to do the following:
Convert richtext to div
Convert par to p
Convert run to span
Convert font to an attribute
In which case, a series of simple templates should do it.
Try this XSLT
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="html" indent="yes" />
<xsl:template match="#*|node()">
<xsl:copy>
<xsl:apply-templates select="#*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="richtext">
<div>
<xsl:apply-templates select="par|table" />
</div>
</xsl:template>
<xsl:template match="par">
<p>
<xsl:apply-templates />
</p>
</xsl:template>
<xsl:template match="run">
<span>
<xsl:call-template name="style" />
<xsl:apply-templates />
</span>
</xsl:template>
<xsl:template match="font" />
<xsl:template name="style">
<xsl:attribute name="style">
<xsl:for-each select="font">
<xsl:if test="position() > 1">; </xsl:if>
<xsl:value-of select="#style" />
</xsl:for-each>
</xsl:attribute>
</xsl:template>
</xsl:stylesheet>
Note the template matching "font" isn't really necessary here. As the font elements in your example have no child, you could omit the template as the built-in templates will just skip over it, and output nothing.
I am trying to use the < sub > < /sub > tag to make parts of my xml file subscripts when opened online but there is an issue when I open up the xml file in Internet Explorer (doesn't say what error just does not look right in IE). I think it is because xml is reading < sub > as another child element but < sub > is just supposed to be used to tell hmtl to make certain parts of the xml file subscripts online. Any ideas on what to change? I am also using xsl to convert xml to html for online publication. The code for that is below
XML File:
<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="ALDformat.xsl"?>
<ALD_data>
<Element Title = "lithium">
<Element>lithium </Element>
<Compound Subtitle = "Li<sub>2</sub>CO<sub>3</sub>">
<Compound> Li<sub>2</sub>CO<sub>3</sub> </Compound>
<Precursor>
<precursor1> Li(thd) </precursor1>
<precursor2> O<sub>3</sub> </precursor2>
<Ref2> Putkonen2009 </Ref2>
</Precursor>
</Compound>
<Compound Subtitle = "Li<sub>2</sub>O(LiOH)">
<Compound> Li<sub>2</sub>O(LiOH) </Compound>
<Precursor>
<precursor1> Li(O<sup>t</sup>Bu) </precursor1>
<precursor2> H<sub>2</sub>O </precursor2>
<Ref2> Aaltonen2010 </Ref2>
</Precursor>
</Compound>
</Element>
</ALD_data>
XSL File:
<?xml version="1.0" encoding="UTF-8"?>
<html xsl:version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<body style="font-family:Arial;font-size:12pt;background-color:#EEEEEE">
<h1>ALD literature XML database</h1>
<p>Last update: 6 January 2016</p>
<xsl:for-each select="ALDdata/Element">
<div style="background-color:teal;color:white;padding:4px">
<span style="font-weight:bold"> Element: <xsl:value-of select="Element"/> </span>
</div>
<xsl:for-each select="Compound">
<div style="background-color:lightgrey;margin-left:20px;margin-bottom:1em;font-size:10pt">
<p>
<span> Compound: <xsl:value-of select="Compound"/> </span>
</p>
</div>
<xsl:for-each select="Precursor">
<div style="margin-left:30px;margin-bottom:1em;font-size:10pt">
<p>
Precursor 1: <xsl:value-of select="precursor1"/> <br/>
Precursor 2: <xsl:value-of select="precursor2"/>
</p>
Post-2005 review paper references
<ol>
<xsl:for-each select="Ref2">
<li><xsl:value-of select="."/></li>
</xsl:for-each>
</ol>
</div>
</xsl:for-each>
</xsl:for-each>
</xsl:for-each>
</body>
</html>
In order for your sub and sup elements to be processed, you'll have to use xsl:apply-templates instead of xsl:value-of for the elements that contain sub and sup.
I don't think you can use a literal result element as a stylesheet and add templates.
Maybe try something like this instead...
XML Input (Note: I had to remove the values of the Compound/#Subtitle attributes as they are not well-formed.)
<?xml-stylesheet type="text/xsl" href="ALDformat.xsl"?>
<ALD_data>
<Element Title = "lithium">
<Element>lithium </Element>
<Compound Subtitle = "">
<Compound> Li<sub>2</sub>CO<sub>3</sub> </Compound>
<Precursor>
<precursor1> Li(thd) </precursor1>
<precursor2> O<sub>3</sub> </precursor2>
<Ref2> Putkonen2009 </Ref2>
</Precursor>
</Compound>
<Compound Subtitle = "">
<Compound> Li<sub>2</sub>O(LiOH) </Compound>
<Precursor>
<precursor1> Li(O<sup>t</sup>Bu) </precursor1>
<precursor2> H<sub>2</sub>O </precursor2>
<Ref2> Aaltonen2010 </Ref2>
</Precursor>
</Compound>
</Element>
</ALD_data>
XSLT 1.0 (ALDformat.xsl)
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/*">
<html>
<body style="font-family:Arial;font-size:12pt;background-color:#EEEEEE">
<h1>ALD literature XML database</h1>
<p>Last update: 6 January 2016</p>
<xsl:apply-templates/>
</body>
</html>
</xsl:template>
<xsl:template match="Element[#Title]">
<div style="background-color:teal;color:white;padding:4px">
<span style="font-weight:bold"> Element: <xsl:apply-templates select="Element"/> </span>
</div>
<xsl:apply-templates select="Compound"/>
</xsl:template>
<xsl:template match="Compound[#Subtitle]">
<div style="background-color:lightgrey;margin-left:20px;margin-bottom:1em;font-size:10pt">
<p>
<span> Compound: <xsl:apply-templates select="Compound"/> </span>
</p>
</div>
<xsl:apply-templates select="Precursor"/>
</xsl:template>
<xsl:template match="Precursor">
<div style="margin-left:30px;margin-bottom:1em;font-size:10pt">
<p>
Precursor 1: <xsl:apply-templates select="precursor1"/> <br/>
Precursor 2: <xsl:apply-templates select="precursor2"/>
</p>
Post-2005 review paper references
<ol>
<xsl:apply-templates select="Ref2"/>
</ol>
</div>
</xsl:template>
<xsl:template match="sub|sup">
<xsl:copy-of select="."/>
</xsl:template>
<xsl:template match="Ref2">
<li><xsl:apply-templates/></li>
</xsl:template>
</xsl:stylesheet>
Output
<html>
<body style="font-family:Arial;font-size:12pt;background-color:#EEEEEE">
<h1>ALD literature XML database</h1>
<p>Last update: 6 January 2016</p>
<div style="background-color:teal;color:white;padding:4px"><span style="font-weight:bold"> Element: lithium </span></div>
<div style="background-color:lightgrey;margin-left:20px;margin-bottom:1em;font-size:10pt">
<p><span> Compound: Li<sub>2</sub>CO<sub>3</sub></span></p>
</div>
<div style="margin-left:30px;margin-bottom:1em;font-size:10pt">
<p>
Precursor 1: Li(thd) <br>
Precursor 2: O<sub>3</sub></p>
Post-2005 review paper references
<ol>
<li> Putkonen2009 </li>
</ol>
</div>
<div style="background-color:lightgrey;margin-left:20px;margin-bottom:1em;font-size:10pt">
<p><span> Compound: Li<sub>2</sub>O(LiOH) </span></p>
</div>
<div style="margin-left:30px;margin-bottom:1em;font-size:10pt">
<p>
Precursor 1: Li(O<sup>t</sup>Bu) <br>
Precursor 2: H<sub>2</sub>O
</p>
Post-2005 review paper references
<ol>
<li> Aaltonen2010 </li>
</ol>
</div>
</body>
</html>
You can't place HTML in a stylesheet right away, your XSLT must have the stylesheet element at the top level, and have template elements as child content, like
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body style="font-family:Arial;font-size:12pt;background-color:#EEEEEE">
<h1>ALD literature XML database</h1>
<p>Last update: 6 January 2016</p>
<xsl:for-each select="ALDdata/Element">
<!-- ... -->
</xsl:for-each>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
I must admit, it's been a while since I used in-browser XSLT. Are you using IE by chance?
I think I never asked a question with such an incomprehensible title, sorry about that.
Let say the XML file I have look like that (not that I don't want to copy/paste, but it's too big):
<A attr1="aaa" attr2="bbb">
<B attr8="23156">
<C attr10="bla"/>
<C attr10="bli"/>
<C attr10="blo"/>
</B>
</A>
<A attr1="jhg" attr2="ygyug">
<B attr8="126">
<C attr10="bla"/>
</B>
<B attr8="102">
<C attr10="bla"/>
<C attr10="blo"/>
</B>
</A>
Well, you got the point, a generic XML file. I don't know the tags, the tags order, and the attributes.
I have to use XSLT to turn this XML into a HTML file with all the "nodes" and attributes of the xml as text, in an equivalent tree :
<div>
<A attr1="aaa" attr2="bbb">
<div>
<B attr8="23156">
<div><C attr10="bla"/></div>
<div><C attr10="bli"/></div>
<div><C attr10="blo"/></div>
</div>
</div>
<div>
<A attr1="jhg" attr2="ygyug">
<div>
<B attr8="126">
<div><C attr10="bla"/></div>
</div>
<div>
<B attr8="102">
<div><C attr10="bla"/></div>
<div><C attr10="blo"/></div>
</div>
</div>
I can get every nodes' name by selecting //node(), I can get attributes by selecting #*, but I can't figure out how to get the html as expected.
Any help you can give will be greatly appreciated :D
Applying the following XSLT to your sample should produce the expected result with a (minor) difference in space before the slash caracter
<?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="*">
<div>
<<xsl:value-of select="name()"/><xsl:value-of select="' '"/><xsl:apply-templates select="#*"/><xsl:apply-templates select="." mode="close-if-leaf"/>>
<xsl:apply-templates select="*"/>
</div>
</xsl:template>
<xsl:template match="*" mode="close-if-leaf">
<xsl:if test="count(*) = 0">/</xsl:if>
</xsl:template>
<xsl:template match="#*">
<xsl:value-of select="name()"/>="<xsl:value-of select="."/>"<xsl:value-of select="' '"/>
</xsl:template>
</xsl:stylesheet>
Have the following XML:
<?xml version="1.0" encoding="UTF-8"?>
<core:renderedItem renderedContentUUID="e8c957a5-03e0-41f4-83a5-297e43bd660f" family="ResearchOutput" type="ContributionToJournal" rendering="harvard" workflows="researchoutput" workflowStates="approved" external="false" classification="/dk/atira/pure/researchoutput/researchoutputtypes/contributiontojournal/article" state="/dk/atira/pure/publication/status/inpress">
<div class="rendering rendering_researchoutput rendering_researchoutput_harvard rendering_contributiontojournal rendering_harvard rendering_contributiontojournal_harvard">
<span>Reid, CT</span>
& Nsoh, W 2014, '
<span class="harvard_title">Whose Ecosystem is it Anyway: Private and Public Rights under New Approaches to Biodiversity Conservation</span>
'
<span>
<em>Journal of Human Rights and the Environment</em>
</span>
.
</div>
</core:renderedItem>
I'm new to XSLT and I'm trying to output the XML using XSLT in the following HTML format:
<div class="publications">
<p>
<span>Reid, CT</span>
& Nsoh, W 2014, '
<span class="harvard_title">Whose Ecosystem is it Anyway: Private and Public Rights under New Approaches to Biodiversity Conservation</span>
'
<span><em>Journal of Human Rights and the Environment</em></span>
.
</p>
</div>
The href link always starts with 'http://some.website.com/portal/en/research/' and the URL needs to be built up from that base + renderedContentUUID. I've managed this (sort of!) with help from others here but I'm stuck with the need to change the HTML output to build in the href etc. Also, the "harvard_title" string has to be changed to all lower case and if there is a colon in the title, I need to just take the string up to the colon. Then all spaces have to be changed into '-'s. This is how the URL looks at present:
http://somewebsite.com/portal/en/research/whose-ecosystem-is-it-anyway(e8c957a5-03e0-41f4-83a5-297e43bd660f).html
My xslt so far:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:core="http://atira.dk/schemas/pure4/model/core/stable"
xmlns:x="http://www.w3.org/1999/xhtml"
exclude-result-prefixes="x">
<xsl:output method="html"/>
<xsl:strip-space elements="*"/>
<xsl:variable name="lower">
abcdefghijklmnopqrstuvwxyz
</xsl:variable>
<xsl:variable name="upper">
ABCDEFGHIJKLMNOPQRSTUVWXYZ
</xsl:variable>
<xsl:variable name="pubURL"/>
<xsl:template match="//*">
<html>
<body>
<h1>Staff Publications</h1>
<xsl:apply-templates/>
</body>
</html>
</xsl:template>
<xsl:template match="//*">
<h2>Journal Articles</h2>
<xsl:for-each select="//core:renderedItem">
<xsl:sort select="#type"/>
<xsl:choose>
<xsl:when test ="#type = 'ContributionToJournal'">
<xsl:variable name="uuid" select ="#renderedContentUUID"/>
<xsl:variable name="show" select="translate(translate((div/span[#class = 'harvard_title']),' ','-'), $upper, $lower)" />
<xsl:if test="contains($show, ':')">
<xsl:variable name="pubURL" select="concat('http://somewebsite.com/portal/en/research/', substring-before($show, ':'),'(',$uuid,').html')"/>
</xsl:if>
<xsl:if test="not(contains($show, ':'))">
<xsl:variable name="pubURL" select="concat('http://somewebsite.com/portal/en/research/',$show,'(',$uuid,').html')"/>
</xsl:if>
<xsl:value-of select ="$pubURL"/>
<div class="publications">
<p>
<xsl:copy-of select="div"/>
</p>
</div>
</xsl:when>
</xsl:choose>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
Can anyone shed some light into this for me. I'm unsure about how to proceed constructing the href from the pubURL and 'inserting' it into the in the HTML output.
It's very difficult to answer your question because (1) your XML is not valid and (2) your current stylesheet is confusing (for lack of better word).
To pinpoint the answer to the exact problem you asked about: if your stylesheet had the following template (in the appropriate place):
<xsl:template match="span[#class='harvard_title']">
<span class="harvard_title">
<a>
<xsl:attribute name="href">
<xsl:text>http://some.website.com/portal/en/research/</xsl:text>
<xsl:value-of select="translate(translate(substring-before(., ':'), $upper, $lower), ' ', '-') "/>
<xsl:value-of select="concat('(', ../../#renderedContentUUID, ').html')"/>
</xsl:attribute>
<xsl:copy-of select="node()"/>
</a>
</span>
</xsl:template>
then this template would write the following output to the result tree:
<span class="harvard_title">Whose Ecosystem is it Anyway: Private and Public Rights under New Approaches to Biodiversity Conservation</span>