I have the following xml:
<article article-type="research-article">
<body>
<graphic xlink:href="zee9991370930006.g.eps"/>
<self-uri xlink:title="pdf" xlink:href="zee00813002857.pdf" />
</body>
</article>
I need to convert this to:
<article article-type="research-article" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:mml="http://www.w3.org/1998/Math/MathML">
<body>
<graphic xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="zee9991370930006.g.eps"/>
<self-uri xlink:title="pdf" xlink:href="zee00813002857.pdf" xmlns:xlink="http://www.w3.org/1999/xlink"/>
</body>
</article>
I used the following command in XSLT 2.0 for each of the elements for which namespace attribute is required:
<xsl:namespace name="xlink" select="'http://www.w3.org/1999/xlink'"/>
<xsl:namespace name="mml" select="'http://www.w3.org/1998/Math/MathML'"/>
But the issue is I am getting the namespace attribute only for one element i.e. article. I have declared the namespaces at the beginning of my xslt as well. Can't figure out what is the exact issue. Help of any kind would be truly appreciated. Thanks.
XML generators are not supposed to do what you want. They will produce your XML according to the specs. It is not recommended that you define the same namespaces in all elements that are using them! this makes it verbose, ugly and weird way of doing tings.
What is the problem if the namespace is defined only at the top (root element)? You can use it only in the elements that require it. simple.
(OP's comment: I need it at the root and I have declared it. But it is not available for the nodes under it i.e graphic and self-uri in my case).
Have you checked if you xml is well-formed? If what you post here is the complete xml, then graphic and self-uri should always have the namespace available. You should aim for the following output for the reasons told above.
<article article-type="research-article" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:mml="http://www.w3.org/1998/Math/MathML">
<body>
<graphic xlink:href="zee9991370930006.g.eps"/>
<self-uri xlink:title="pdf" xlink:href="zee00813002857.pdf"/>
</body>
</article>
Related
EDIT: solved - incorrect path to the XML document. I'll leave this embarrassing question up in the hope that it may help others.
Environment: eXist-db 4.2.1 , XQuery 3.1, XSLT 2.0
I am building a webpage from a number of templates in eXist-DB, the last of which calls an XSL transformation to produce a fragment of HTML.
The XSL transformation works when I test it outside eXist-DB. At this XSLT fiddle, you have the complete XSLT file and a representative XML doc that should be transformed. It produces the expected HTML without error. Oxygen also produces the transformation without error.
Yet when I execute the transformation in eXist-db XQuery, it signals execution...but it produces no output!
The XAR file for this project (with all modules and files included) can be downloaded here: https://www.dropbox.com/s/gtg4lpv9jsh822e/deheresi-0.1.xar
This is the XQuery transform function that should produce the HTML fragment:
declare function document:doc-xsl-docview($node as node(),
$model as map(*), $currentdoc as xs:string)
{
let $currentdocnode := doc(concat($globalvar:URIdb,$currentdoc))
let $xi := concat("xinclude-path=", $globalvar:URIdb)
let $xsltdoc := doc(concat($globalvar:URIstyles,
"ms609__testxsl-withmodes.xsl"))
let $xsltransform := transform:transform(
$currentdocnode,
$xsltdoc,
(<parameters>
<param name="paramPersonurl" value="{$globalvar:URLperson}"/>
<param name="paramPlaceurl" value="{$globalvar:URLplace}"/>
<param name="paramDocurl" value="{$globalvar:URLdoc}"/>
</parameters>),(),$xi)
return $xsltransform
};
This is the HTML (in document.html) calling the function in a template (the last template call). All the other doc-sidebar templates execute perfectly. <div class="col-md-10 document-view"> outputs as an empty div.
<div xmlns="http://www.w3.org/1999/xhtml" data-
template="templates:surround" data-template-
with="templates/site_wrapper.html" data-template-at="content">
<div class="col-md-12 document-title">
<h2>
<span class="en">Deposition: Arnald Donat</span>
<span class="fr">Déposition : Arnald Donat</span>
</h2>
</div>
<div class="col-sm-12">
<div class="col-md-2 sidebar">
<div data-template="document:doc-sidebar-sub1" data-template-currentdoc="ms609_0013.xml"/>
<div data-template="document:doc-sidebar-sub2" data-template-currentdoc="ms609_0013.xml"/>
<div data-template="document:doc-sidebar-sub3" data-template-currentdoc="ms609_0013.xml"/>
<div data-template="document:doc-sidebar-sub4" data-template-currentdoc="ms609_0013.xml"/>
</div>
<div class="col-md-10 document-view">
<div data-template="document:doc-xsl-docview" data-template-currentdoc="ms609_0013.xml"/>
</div>
</div>
</div>
As part of my testing, I did the following: I hardcoded the expected HTML fragment into an XSL file (texthtmlonly.xsl) and called it from the same function instead. It produces the output successfully.
At this point I can't see any reason why the XSL transformation shouldn't work:
the XSL and XML files produce valid results without error (outside eXist)
the XQuery transform produces results with a hardcoded XSL file
the HTML calls all templates without error
Many thanks in advance.
NB: the TEI-XML file (ms609_0013.xml) is temporarily hardcoded for testing in eXist-DB.
EDIT: solved - incorrect path to the XML document. I'll leave this embarrassing question up in the hope that it may help others.
I have a xml structure like below:
<PAGES>
<PAGE>
<PAGENUMBER>1</PAGENUMBER>
<SECTION>
<SECTIONITEM>
<ITEMNUMBER>1</ITEMNUMBER>
<TITLE>Interactive Forms</TITLE>
<TOPIC>
<SUBTITLE>Intro to Forms & Attributes </SUBTITLE>
<ITEM>1</ITEM>
<PARA>This is the explanation for Topic ITEM 1</PARA>
<GRAPH>This the the link to the GRAPHIC</GRAPH>
</TOPIC>
</SECTIONITEM>
</SECTION>
</PAGE>
....<!-- lots of page blocks-->
</PAGES>
Now I have to generate a html summary that will list the PAGENUMBERs when certain conditions are satisfied and generate an <a href> link for the PAGENUMBER in the html. The request is that when user clicks on the page number link on the html, xml file will be popped up and directed to the related xml content.
Is this possible to link PAGENUMBER to the related xml content using xsl? I don't have enough experience to do this now.
Could anybody give me some suggestion or this could be done using other language like java or javascript?
Many thanks in advance!
When splitting a deeply nested XML document into multiple output files using result-document(), is there a method to rewrite the #href values to point to ids inside the new documents? For example, splitting a book into multiple documents based on each becoming a new file, named with book-part/#id. In output file for chapter 1 there may be a link to a target in output file for chapter 2, which link value used to be relative within the single file. Now this link pointing to a different file should have the file name of chapter 2 followed by # and the original target value. There are changes to make the proper linking element (related-object), too, but it is the target value that I'm trying to generate specifically.
i.e link target pattern: [outputfilename.xml]#[original-filetarget-id]
It seems that I need to gather the values of each #rid in the original file and check before I insert the filename if the target will be in a different file and write the output #document-id according to the file in which it will be output. But I'm having trouble understanding how I would know the output file name and where in the XSLT to rewrite the target.
source xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE book PUBLIC "-//NLM//DTD Book DTD v2.1 20050630//EN" "book.dtd">
<book dtd-version="3.0">
<book-meta>
<book-id>123.4567890</book-id>
</book-meta>
<body>
<book-part book-part-type="chapter" id="book.123.4567890.ch01">
<book-part-meta>
<title-group>
<title>Chapter 1</title>
</title-group>
</book-part-meta>
<body>
<p> some text with a <xref rid="a">link to chapter 1</xref></p>
<p> some text with a <xref rid="b">link to chapter 2</xref></p>
<p id="a">a target id in chapter 1</p>
</body>
</book-part>
<book-part book-part-type="chapter" id="book.123.4567890.ch02">
<book-part-meta>
<title-group>
<title>Chapter 2</title>
</title-group>
</book-part-meta>
<body>
<p> some text with a <xref rid="a">link to chapter 1</xref></p>
<p> some text with a <xref rid="b">link to chapter 2</xref></p>
<p id="b">a target id in chapter 1</p>
</body>
</book-part>
</body>
</book>
output book.123.4567890.ch01.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE book PUBLIC "-//NLM//DTD Book DTD v2.1 20050630//EN" "book.dtd">
<book dtd-version="3.0" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:oasis="http://docs.oasis-open.org/ns/oasis-exchange/table">
<book-meta>
<book-id>123.4567890</book-id>
</book-meta>
<body>
<book-part book-part-type="chapter" id="book.123.4567890.ch01">
<book-part-meta>
<title-group>
<title>Chapter 1</title>
</title-group>
</book-part-meta>
<body>
<p> some text with a <xref rid="a">link to chapter 1</xref></p>
<p> some text with a <related-object document-type="chapter" object-id="book.123.4567890.ch02.xml#b">link to chapter 2</related-object></p>
<p id="a">a target id in chapter 1</p>
</body>
</book-part>
</body>
</book>
output book.123.4567890.ch02.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE book PUBLIC "-//NLM//DTD Book DTD v2.1 20050630//EN" "book.dtd">
<book dtd-version="3.0" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:oasis="http://docs.oasis-open.org/ns/oasis-exchange/table">
<book-meta>
<book-id>123.4567890</book-id>
</book-meta>
<body>
<book-part book-part-type="chapter" id="book.123.4567890.ch02">
<book-part-meta>
<title-group>
<title>Chapter 2</title>
</title-group>
</book-part-meta>
<body>
<p> some text with a <related-object document-type="chapter" object-id="book.123.4567890.ch01.xml#a">link to chapter 1</related-object></p>
<p> some text with a <xref rid="b" >link to chapter 2</xref></p>
<p id="b">a target id in chapter 1</p>
</body>
</book-part>
</body>
</book>
The short answer is: yes, you have understood correctly what you need to do.
You need to figure out, for each hyperlink, whether its target will be in the same output file as the source of the link, or a different one. And you have correctly identified the challenge here: knowing what the new file name will be. It's not really as difficult as it may look at first; just take a deep breath and work it out.
You are at an xref element; it has an rid attribute. You want to know: will the xref and the target be in the same output file or different ones? To decide this, you must
Ascend from the xref element to the containing book-part, and figure out what its filename will be. Put this value in a variable (fn-xref).
Go to the target element (id(#rid)) and then ascend from that element to the containing book-part, and figure out what its filename will be. Put this value in a variable (fn-rid).
Compare the values of $fn-xref and $fn-rid. If they are equal, do the right thing. If they differ, do the other right thing.
I'm guessing you don't need help turning this prose description into XSLT, but speak up if you do.
I am having a slight problem with making a twitter bootstrap dynamic in XSLT. I don't even know if what I am doing is possible as the variables in XSLT are not changeable. Here is my code:
<xsl:for-each select="category">
<div class="accordion-heading">
<a class="accordion-toggle" data-parent="#accordion2" data-toggle="collapse" href="#collapseOne">
<xsl:value-of select="title"/>
</a>
</div>
Basically, for each category, I need a new href to be created. Right now, it is set to collapseOne. I have tried a number of things such as position() to try to make this dynamic, but I cannot figure it out. Any input would be appreciated. If clarification or more code is required, please say so. I am new to posting on this forum. Thanks
The standard XSLT function generate-id() was created having in mind exactly this class of use-case scenarios.
I have the following simple Diazo rules file:
<rules
xmlns="http://namespaces.plone.org/diazo"
xmlns:css="http://namespaces.plone.org/diazo/css"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<theme href="theme/theme.html" />
<replace css:theme-children="#content" css:content-children=".content" />
</rules>
and theme:
<html>
<body>
<div id="content">
Lorem ipsum ...
</div>
</body>
</html>
The source I want to transform is:
<html>
<body>
<div class="content">
info
</div>
</body>
</html>
What I get is
... info ...
but I want to keep the HTML entities of the href attribute intact. How can I do this with Diazo?
Note numeric character references are not entity references so your title is a bit misleading (the answer for preserving or not entity references such as "& n b s p ; " is very different)
I don't know Diazo but in XSLT if you add
<xsl:output encoding="US-ASCII"/>
to your document then any non ascii characters will be output using numeric references.
However in your example they are in fact ascii characters that are quoted such as "." as "." There isn't any standard way in xslt 1 to do that (and there should never be any reason to do that if the document is going to be processed by a conforming html or xml system). Any such system will expand those references to their characters before processing starts. (Which is why XSLT can not preserve them: they have been removed by the xml parser before XSLT sees the input data.)