How to retain mathml tags after transformation? - mathml

How do I retain mathml tags after the transformation? I'm using this:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:m="http://www.w3.org/1998/Math/MathML">
By the way I'm using the m namespace. After transforming into html, mathml tags are gone. Please help.

You are using XSLT so that takes some unspecified input and can generate any XML output. Since you have given no indication of the input or the transformation it is pretty hard to help but as a wild guess
<xsl:template match="m:*">
<xsl:copy-of select="."/>
</xsl:template>
will copy mathml from the input to the output if templates are applied to the mathml elements.

Related

Simple xml document with Css

Hi i am new in programming i am creating a simple xml document and i want to apply Css in my xml data . My xml is
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE Customers SYSTEM "customers.dtd">
<Employees>
<Employee>
<FirstNameLabel>FirstName:</FirstNameLabel>
<FirstNameData>Ana</FirstNameData>
<FirstNameLabel>LastName:</FirstNameLabel>
<FirstNameData>Ali</FirstNameData>
</Employee>
<Employee>
<FirstNameLabel>FirstName:</FirstNameLabel>
<FirstNameData>Ash</FirstNameData>
<FirstNameLabel>LastName:</FirstNameLabel>
<FirstNameData>Ana</FirstNameData>
</Employee>
</Employees>
I need to display results as
FirstName: Ana
LastName: Ali
FirstName: Ash
LastName: Ana
While FirstName and LastName should be green while Values should be red
Help would be appreciated Thanks
I don't think you looked before posting this. w3schools shows exactly how. http://www.w3schools.com/xml/xml_display.asp It is very similar to adding a style sheet to html. Also, you should fix your indentation.
Try:
FirstNameLabel{
float:left;
}
FirstNameData{
clear:left;
}
I believe you may want to look to use XML Stylesheet to render and format your XML files rather than CSS. CSS is, as far as I know, for HTML documents. In your case, you would need to create a XSLT sheet, which is pretty much XML that specifies how to present each of your node. below is a quick example (untested):
<?xml version="1.0" encoding="ISO-8859-1"?>
<html xsl:version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml">
<body style="font-family:Arial;font-size:12pt;background-color:#EEEEEE">
<xsl:for-each select="Employees/Employee">
<p>Firstname: <xsl:value-of select="FirstNameData"/>.</p>
<p>Lastname: <xsl:value-of select="LastNameData"/>.</p>
</div>
</xsl:for-each>
</body>
</html>
Note that you shouldn't need to store labels in your XML. You can have them in your stylesheet.

How to convert a xml element into url using css?

I have an xml file which has an element like this
<video><title>XXXX</title><url>VIDEO ID OF YOUTUBE></url></video>
Is there any way to use CSS to display the elements as
XXXX
CSS is for Styling, if you wish to read XML and produce HTML Content you should use Javascript. Or any server side language if you want it to be done before sending it to the client browser.
As Nicklas points out, many think of Css to be intended to be for styling and nothing more. More generally, though, it's intended for the presentation of your information. This is a fringe case that's difficult for me to say whether it's going too far or within the scope of CSS: is this simply changing the presentation, or is it doing something more?
I'm sure many, like Nicklas, would argue that what you want to do goes beyond the intended purpose of CSS. And I'd probably agree with Nicklas in that for most cases I'd find this to be a less-than-ideal way to go about things.
With that said, it is possible
#url:before {
display: inline-block;
content: "<a href=\"http://www.youtube.com/";
}
#url:after {
display: inline-block;
content: "\">";
}
#text:after {
display: inline-block;
content: "</a>";
}
Note: I used Html in this example for the sake of making a JsFiddle, but the same strategy should work for an Xml file
I do not know of a way to use CSS for this. But you can do this using a XSLT Stylesheet. Is that what you want? Then a XSLT Stylesheet similar to this can help you:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"
>
<xsl:output method="html" indent="yes"/>
<xsl:template match="/" >
<body>
<xsl:apply-templates select ="/items/video"/>
</body>
</xsl:template>
<xsl:template match="video" >
<li>
<a>
<xsl:attribute name="href">
<xsl:value-of select="./url" disable-output-escaping="yes" />
</xsl:attribute>
<xsl:value-of select="./title"/>
</a>
</li>
</xsl:template>
<xsl:template match=
"*[not(#*|*|comment()|processing-instruction())
and normalize-space()=''
]"/>
<xsl:template match="text()"/>
</xsl:stylesheet>
This assumes that the XML input file looks as follows:
<?xml version="1.0" encoding="utf-8" ?>
<items>
<video>
<title>XXXX</title>
<url>VIDEO ID OF YOUTUBE></url>
</video>
<video>
<title>XXXX</title>
<url>VIDEO ID OF YOUTUBE></url>
</video>
</items>
Exactly how you should do the transform is hard to say when I don't know about your requirements. A XSLT transform can be done in a number of ways. If the XML input file is static one can let the webbrowser do the transformation. If the XML file is on a server you can write a transform in a awebpage and sen the HTML to the webbbrowser. It all depens on your environment.

Creating anchor links in rich text fields with SDL Tridion 2011 SP1

I am trying to use the anchor button in a RTF field of a Component, and getting unexpected behavior. Using the Chrome Browser from the design view, I highlight/select the heading (i.e. <h2>My Heading</h2>) I want to use as an anchor, and press the anchor button and enter the anchor name (i.e. my_place).
This results in the following code being displayed in my source tab:
<a name="my_place" id="myplace"/><h2>My Heading</h2>
This causes render problems when displaying the HTML in a browser due to the self closing <a/> tag.
I would have expected one of the following three HTML fragments being inserted into the HTML source:
<a name="my_place" id="myplace"><h2>My Heading</h2></a>
or
<h2><a name="my_place" id="myplace">My Heading</a></h2>
or
<a name="my_place" id="myplace"><a><h2>My Heading</h2>
Has anyone else experienced this? or know of a way to achieve what I had expected (without manually editing the HTML). Or is this a bug in the current version of the product.
Attached is my sample XSLT template:
<template match="a[(#name) and (count(node()) = 0)]">
<copy>
<apply-templates select="#*"/>
<xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" class="hidden"> </xhtml:span>
</copy>
</template>
This adds a bit more than strictly needed, but handles some other issues we have due to XML manipulation on the Content Delivery side.
Essentially it matches all empty a tags with a name attribute, and add something between them in order to stop them self closing. In our case we post process all of the XML with XSLT, so we have challenges with empty tags getting closed all the time. So as a dirty hack, we are now inserting a hidden span tag between empty tags to prevent the issue.
Thanks Chris, I've edited your solution to fit my requirements so wanted to share for anyone with this issue in the future.
Note: This moves the text inside the anchor and deletes the text outside. Fixes anchors that were intended to contain text only, not html. i.e
My solution fixes this tag:
<p><a name="anchor1" id="anchor1"></a>Anchor text</p>
To
<p><a name="anchor1" id="anchor1">Anchor text</a></p>
But not this:
<p><a name="anchor1" id="anchor1"></a><h1>Anchor text</h1></p>
Here's my xsl. Hopefully it will help give you a base, I'm sure you could easily update it to look for a following tag (I don't require this for my solution).
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" method="html" cdata-section-elements="script"/>
<xsl:template match="/ | node() | #*">
<xsl:copy>
<xsl:apply-templates select="node() | #*"/>
</xsl:copy>
</xsl:template>
<!-- fixes Tridion bug when using interface button to insert anchor in rich text field -->
<!-- gets all empty anchor tags with an id and takes any following text and copies it inside anchor -->
<xsl:template match="a[(#id) and (count(node()) = 0)]">
<xsl:copy>
<xsl:for-each select="#*">
<xsl:attribute name="{name(.)}">
<xsl:value-of select="."/>
</xsl:attribute>
</xsl:for-each>
<xsl:value-of select="normalize-space(following-sibling::text())"/>
</xsl:copy>
</xsl:template>
<!-- delete any text after an empty anchor (template above has already copied this text inside the anchor) -->
<xsl:template match="text()[preceding-sibling::a[(#id) and (count(node()) = 0)]]" ></xsl:template>
</xsl:stylesheet>
Here's my test XML
<?xml version ="1.0"?>
<?xml-stylesheet type="text/xsl" href="tridionhtmlfield.xsl"?>
<html>
<head></head>
<body>
<p><a id="anchorlink" name="anchorlink" title="Anchor link" href="#Anchor">Anchor link</a>Some text after</p>
<p><a name="broken-with-html-name" id="broken-with-html-id"></a><h1>Anchor - broken with html</h1></p>
<p><a name="broken-text-only-name" id="broken-text-only-id"></a>Anchor - broken text only</p>
<p><a name="broken-notext-name" id="broken-notext-id"></a></p>
<p><a name="correct-name" id="correct-id">Anchor - correctly rendered</a> Some text after</p>
</body>
</html>
After transform:
<html>
<head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"></head>
<body>
<p><a id="anchorlink" name="anchorlink" title="Anchor link" href="#Anchor">Anchor link</a>Some text after</p>
<p><a name="broken-with-html-name" id="broken-with-html-id"></a><h1>Anchor - broken with html</h1></p>
<p><a name="broken-text-only-name" id="broken-text-only-id">Anchor - broken text only</a></p>
<p><a name="broken-notext-name" id="broken-notext-id"></a></p>
<p><a name="correct-name" id="correct-id">Anchor - correctly rendered</a> Some text after</p>
</body>
</html>
Hope this helps
It looks like a bug to me Chris. I've just confirmed it on Chrome, Firefox and IE. It's completely counter-intuitive that the current text selection should be ignored. (On the plus side, once you fix it manually in the source tab, everything appears to behave perfectly.)
I suggest that you report this to Tridion, and perhaps work around it by altering your templating or filter XSLT.
It is a bug in Tridion. One work-around that I suggest (and have implemented in our particular installation) is to do the following:
Edit the FormatAreaStyles.css file (found in the Tridion CMS program files) — as well as your CSS file used by the website — to include a class like this:
.hiddenanchor {
width:1px;
height: 1px;
display: block;
text-indent:-50000px;
}
Publish out your CSS file (with the new class) so that it'll format your anchors properly.
And then in the component where you are building out the anchors, you will have to:
a. type a word or series of words in your component (where you want the target to be),
b. select that text, and apply the anchor tag to it,
c. then apply the new class you've created (.hiddenanchor) to the anchor.
In the end, your "invisible" anchor would look like this:
<a name="anchorname" id="anchorname" class="hiddenanchor">Anchor Name</a>
It's a crude work-around — fully acknowledged. But it works. You don't end up with the hyperlink/underline styling until the close of the next DOM object.
As an explanation to the CSS, the anchor technically has to be visible in the DOM for it to work and to be accessible by the anchor link. So "display: none" won't work. Alternatively to taking the text-indent approach, you could absolute or fixed position the text off the screen as well.

I want to remove XSL whitespace from Markdown formatting

Markdown formatting is coming into my XSL and maintaining its whitespace and breaks. I want it to be converted to actual HTML elements to remove all whitespace.
Here's a look at the incoming data & HTML source, and here's the code used to process it..
<xsl:value-of select="description-continued" disable-output-escaping="yes" />
The XSL output method already contains indent="no"
You may just need (in case no group of whitespace characters really matters):
<xsl:template match="text()">
<xsl:value-of select="normalize-space()"/>
</xsl:template>
<xsl:value-of select="normalize-space(description-continued)" disable-output-escaping="yes" />

XSLT renders > and < for >< how to do I get around this?

I have some code wrapped in a CDATA tag in an xslt file:
<span>
<xsl:text><![CDATA[<asp:LinkButton ID ="]]></xsl:text><xsl:value-of select="ID"/>
<xsl:text><![CDATA[" onclick="LinkClicked">]]></xsl:text >
<xsl:value-of select="."/>
<xsl:text><![CDATA[</asp:LinkButton>]]></xsl:text>
</span>
When it renders in the page it is > and <, how do I get around this?
Now I know a work around as I can do a replace within the string after this is rendered, but this doesn't seem like the best approach.
You need to change your XSLT code:
<span>
<asp:LinkButton ID="{ID}" onclick="LinkClicked">
<xsl:value-of select="."/>
</asp:LinkButton>
</span>
All this CDATA juggling is not only bad for everybody's eyes, but also the wrong approach no matter how you look at it.
Declare the asp namespace in XSLT and use actual ASP.NET code, not text that looks like code.
This doesn't answer your question, but there is another way to include .net tags.
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:asp="remove">
Note the xmlns:asp="remove"
No need to wrap your control tag in xsl:text or in a cdata section.
Why are you wrapping a tag in a CDATA? The behavior you're describing is exactly what you'd expect, which is why people use CDATA for content, which they want to be escaped.

Resources