Jump to content

XSL Starter Problem


Recommended Posts

Hello, I have dealt quite a lot with XML in the past, now i have to delve into XSL.A text needs to be transformed, and, although i read and understood several tutorials, i still can not see what on earth i am doing wrong. I am sure this will be a minor mistake, any help will be appreciated. My XML:

<?xml version="1.0" encoding="UTF-8"?>
<!--<?xml-model href="http://www.tei-c.org/release/xml/tei/custom/schema/relaxng/teilite.rng" schematypens="http://relaxng.org/ns/structure/1.0"?>-->
<?xml-stylesheet type="text/xsl" href="tmzb.xsl" ?>
<TEI xmlns="http://www.tei-c.org/ns/1.0">
	    <p>Publication information</p>
	    <p>Information about the source</p>
	  <head>Erstes Kapitel</head>
	  <p>Ein einfacher junger Mensch reiste im Hochsommer von Hamburg, seiner Vaterstadt, nach
	    Davos-Platz im Graubündischen. Er fuhr auf Besuch für drei Wochen.</p>
	  <p>Von Hamburg bis
	    dort hinauf, das ist aber eine weite Reise; zu weit ei- gentlich im Verhältnis zu einem so
	    kurzen Aufenthalt. Es geht durch meh- rerer Herren Länder, bergauf und bergab, von der
	    süddeutschen Hochebene hinunter zum Gestade des Schwäbischen Meeres und zu Schiff über seine
	    springenden Wellen hin, dahin über Schlünde, die früher für unergründlich 10 galten.</p>


<?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>    <h2>	    <xsl:value-of select="/TEI/text[1]/front[1]/div1[1]/head[1]"/>	       </h2>  </body>  </html> </xsl:template> </xsl:stylesheet>

Link to comment
Share on other sites

Your XML uses namespaces.To reference a namespace in XSLT (or really, in XPath), you need to register it first. You can do that by choosing an arbitrary prefix at the top of the XSLT. The only important part is that the URI is exactly the URI at your XML. e.g.

<?xml version="1.0" encoding="ISO-8859-1"?><xsl:stylesheet version="1.0"xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:t="http://www.tei-c.org/ns/1.0">   <xsl:template match="/">  <html>  <body>    <h2>            <xsl:value-of select="/t:TEI/t:text[1]/t:front[1]/t:div1[1]/t:head[1]"/>               </h2>  </body>  </html> </xsl:template> </xsl:stylesheet>

Link to comment
Share on other sites

  • 2 weeks later...

Sorry, i think i still did not get the namespace thing. When i am processing my XML, i get this as a result:

<p xmlns=""> text here </p>

I assume the empty brackets are not correct here? What am i doing wrong? The top of my XML document is this:

<?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet type="text/xsl" href="tmzb.xsl"xmlns="http://www.tei-c.org/ns/1.0"?>

And the top of my XSL:

<?xml version="1.0" encoding="UTF-8"?><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"	xmlns:t="http://www.tei-c.org/ns/1.0">

Any help, again, appreciated.

Link to comment
Share on other sites

That shouldn't be happening... But there's three ways you could try and remedy it. 1. Force the output to be HTML, by using the xsl:output element, e.g.

<?xml version="1.0" encoding="UTF-8"?><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"		xmlns:t="http://www.tei-c.org/ns/1.0"><xsl:output method="html" />

2. Accept the fact that there will be a namespace in the output, and make it explicitly be the XHTML namespace, i.e.

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"		xmlns:t="http://www.tei-c.org/ns/1.0" xmlns="http://www.w3.org/1999/xhtml">

3. Maybe (just maybe, I'm not sure), the cause is... well... it's hard to explain without lots of terminology, so let's just say "try this":

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"		xmlns:t="http://www.tei-c.org/ns/1.0" exclude-result-prefixes="t">

Link to comment
Share on other sites

The tags in your source are in the "http://www.tei-c.org/ns/1.0" namespace, while the tags in the output are in no namespace.XSLT's copy-of makes sure the copy is also like that.There are a few ways to work around this, but the easiest would be to edit your XML so that the XHTML elements actually use the XHTML namespace and alter the top of the XSLT to use the 2nd method above.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...