bezier Posted January 21, 2013 Share Posted January 21, 2013 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"> <teiHeader> <fileDesc> <titleStmt> <title>Title</title> </titleStmt> <publicationStmt> <p>Publication information</p> </publicationStmt> <sourceDesc> <p>Information about the source</p> </sourceDesc> </fileDesc> </teiHeader> <text> <body> <head>Erstes Kapitel</head> <head>Ankunft</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> </body> </text> </TEI> My XSL: <?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 More sharing options...
boen_robot Posted January 22, 2013 Share Posted January 22, 2013 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 More sharing options...
bezier Posted February 5, 2013 Author Share Posted February 5, 2013 thank you, will read deeper into namespaces Link to comment Share on other sites More sharing options...
bezier Posted February 6, 2013 Author Share Posted February 6, 2013 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 More sharing options...
boen_robot Posted February 10, 2013 Share Posted February 10, 2013 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 More sharing options...
bezier Posted February 10, 2013 Author Share Posted February 10, 2013 Thank you so much, first method method worked right away. Link to comment Share on other sites More sharing options...
bezier Posted February 10, 2013 Author Share Posted February 10, 2013 This is weird... It worked for the paragraphs now, but i added some tags and i have the same problem with different tags now. It happens wherever i use this line of code: <xsl:copy-of select="."/> Link to comment Share on other sites More sharing options...
boen_robot Posted February 11, 2013 Share Posted February 11, 2013 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 More sharing options...
bezier Posted February 13, 2013 Author Share Posted February 13, 2013 Thank you once more. Your hint helped solve the problem in the browser, though not when transforming XML in Oxygen. In case anyone finds this with a similar problem, what finally solved it for me was changing the Transformator to Xalan. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now