I have an XML document which references a XSL file for the output of HTML.
In the XSL file I have put in various "<xsl:value-of select="fieldname" />" tags referencing items in my XML File.
However for the items I have not mapped they just appear as a long string at the bottom of the html page?
Do I really need to omit all my xml data items not referenced in the XSL file for them to go away or is there a trick to this or a bug in my XSL file?
j
This is result of the XSLT Processing Model.
XSLT uses its *built-in templates` if a node should be processed and no template in the XSLT code is matching it. The built-in template that matches a text node copies it.
Solution:
Add this template that overrides the XSLT built-in template for text nodes:
<xsl:template match="text()"/>
This causes any text node not matched by a more specific template in the code (and not copied with xsl:copy-of or xsl:value-of) to be ignored ("deleted").
Related
We author our documentation in XML and package it to a JSON file to render it on a tablet. But, the basic inline formatting (bold, italics, superscript, and subscript) does not get converted to the JSON. It is plain text. Is there a way to get the tablet/JSON file to include the formatting? Like, attaching a CSS or something? If yes, then what's the effort?
AFAIK, XML does not include any information about formatting either, would need to look at an example on how you include that information in XML, and maybe do something similar in json.
You can use XSLT to transform XML to JSON.
There is already a stylesheet to get you started at: XSLTJSON: Transforming XML to JSON using XSLT
This may be simple, although i'm having some trouble finding a solution.
i create a sitemap for my website in an xml file.i display content of xml file in aspx file.
but i want display xmlfile not in aspx.
when i use response.redirect("sitemap.xml"),it shows tree but i want to show only all content in sequential not in tree.
like this:
content of xmlfile:
<t><t1 p="s1"></t1><t2 p="s2"></t2></t>
but i want address bar=sitemap.xml and show like this:
p=s1p=s2 .....
any idea?
Some browsers will respect XSL declarations at the top of xml files. If you have such a declaration at the top of your xml file like this:
<?xml-stylesheet type="text/xsl" href="YourTransform.xsl"?>
It will apply the transform specified allowing you to output the xml however you want. However, support is not universal.
We did upgrade from Tridion 5.3 to Tridion 2011 SP1.
In Tridion 5.3 we were using VBScript Templates, as a part of this upgrade we are converting existing VBScript Templates to Compound Component Templates. We are facing below mentioned two issues with the content of RTF field.
Issue 1 : In our existing content of RTF field we have empty tags/HTML Tags at number of locations. eg.<a name="Contact" id="Contact"></a> When we publish the content with Compound Component Templates (Tridion 2011 SP1 environment) above mentioned anchor tag is getting converted to <a name="Contact" id="Contact" />. This is breaking existing javascript functionality. To overcome the issue we have written C# functions which finds empty tags and replace the inner text with like <a name="Contact" id="Contact"> </a> then things are working fine. But to call this function at CT level for each RTF field is big activity as we have number Component Tempate. Is there any better way to do it.
Issue 2 : In the same RTF field we have content like (may be editors have copy pasted it from web or somewhere), so when we try to publish page or component it is getting failed with error.
JScriptException:Expression valueUnterminated String Constant.
Is there any default TBB which will help to fix the issues?
Issue 1:
You can also use a Filtering XSLT to modify your RTF content on component save.
This way you can replace any empty tag <tag></tag> with <tag> </tag> on component save and don't need any further change on templating.
Issue 2:
seems like an encoded , see character codes: http://www.escapecodes.info/
Maybe you can replace this character codes with the proper html encoding, using a filtering xslt or a C# TBB
As you already have a function for converting inline closed anchor tags to anchor tags with a non-breaking space in them you could consider using this function from your page template(s) instead of using it in every component template; this would require a much smaller number of templates to change...
You also might want to consider replacing inline closed anchor tags with properly closed anchor tags without actually inserting extra spaces.
Below is a C# fragment you can use in a TBB to replace inline closed anchor tags:
Item outputItem = package.GetByName(pcakge.OutputName);
package.Remove(outputItem);
string outputString = Regex.Replace(outputItem.GetAsString(), "(<a[^>]*?)/>", "$1></a>", RegexOptions.Singleline);
outputItem.SetAsString(outputString);
package.PushItem(Package.OutputName, outputItem);
You could extend it to also replace with but this should not cause any issues as is a valid escape sequence in HTML (Tridion RTF fields are essentially XML which could be the cause for appearing instead of ...).
I am parsing web service xml and populating a treeview in asp.net. I'm trying to display one of the xml node attributes as a tooltip, but that attribute happens to sometimes have html tags in it. I know there seem to be some custom tooltip stuff out there, but I don't have the time or the experience to play with those yet. Is there no way to easily remove such code or translate it into the textual equivalent? I know I can replace br tags with environment.newline, but I don't want to have to do this for every conceivable html tag that might be embeded in the content!
The HTML Agilty Pack is an HTML parser that can read HTML fragments - you can do that and then read the InnerText property of the top node. The effect will be a textual version of the HTML.
So far all the XML / XSLT I've worked with takes an XML document and transforms it to a standalone HTML webpage using an XSLT file.
In my web application, I'm using a web service to retrieve the XML document, which I need to render and make human-readable, and then insert that formatted content into a content placeholder in my master page.
The easiest way would be to append the XSLT to the retrieved XML file and link that to the content placeholder, but something tells me I can't just do that.
I took a look at these Stack Overflow pages, but they just want to render the straight XML whereas I want a transformed XML. Also, I need to be able to put it into my master page template.
This article shows how:
http://www.codeproject.com/Articles/37868/Beginners-Introduction-To-XSL-Transform-Rendering-XML-Data-using-XSL-Get-HTML-output.aspx
even if the spelling is as bad as mine...
Added
And here's another link that shows how, perhaps a bit more simply
http://www.aspfree.com/c/a/XML/Applying-XSLT-to-XML-Using-ASP.NET/2/