How do I store HTML/XHTML in an XML file and then use XSLT to retrieve it? - html

I have an xml file containing the documentation from a project of mine. I'm using XSLT to transform this XML file into HTML to output it in a browser.
Now the thing is that I have some entities that contain some html code. Nothing complicated, just some ` tags. But I don't seem to be able to make it work. I have tried "disable-output-escape" but it only works in internet explorer.
Now I'm trying with namespaces. I wrote this in my root tag.
xmlns:h="http://www.w3.org/1999/xhtml"
and then changed my <br/> tags to <h:br/>, but now the tags don't appear and I still don't have the line break.
I assume I'm missing something.

Found my mistake. Had to use copy-of instead of value-of.

Related

Display doctype tag in html

I'm trying to display a few lines of xml in a manual to be copied and pasted. However, I cannot find a way to display
<!doctype login[ ...
and a few other xml tags. I cannot have extra characters or such, as a client will copy and paste the code.
Htmlentities doesn't solve the issue.
Anyone have any ideas?
A solution I found was to put parts of the tag in their own spans.
<span><</span><span>!</span>DOCTYPE <span>></span>
displays a doctype tag properly.
properly

Handling line breaks from XML to HTML

I am trying to access data within XML tags, but my code only returns data up until the line break.
Here is my XML code:
<job_description>
App Building
<BR/>
More App Building
<BR/>
Even More App Building
</job_description>
Here is my HTML code:
document.write(record[i].getElementsByTagName("job_description")[0].childNodes[0].nodeValue);
At the moment, my page only returns the first part of the data in the "job_description" tags, in this case "App Building", but I would like to be able to return all of the data within the "job_description" tags, including what is inside the line breaks. Any suggestions on ways to handle the XML line breaks. Thanks.
XHTML documents must use lower case for all HTML element and attribute names. This difference is necessary because XML is case-sensitive.
See documentation.

Run a regular expression into a new file (or another existing file)

I would like to take some stuff from file A and reformat it to stick into file B using regular expressions. I am kind of new to vim so this may be a dumb question but I could not find the solution to this anywhere. I guess I am searching for the wrong phrases. Anyway, here are the details of what I want to do. I have a static html page that I would like to have an RSS feed for. Luckily, this page is mostly links to various news items, so creating the RSS will be pretty easy.
I have the regular expression ready:
:%s/^<a href="\(.\{-}\)".title="\(.\{-}\)">\(.\{-}\)<\/a>/<title>\3<\/title>\r<link>\1<\/link>\r<description>\2<\/description>
My problem is I do not want to make the changes in the html file that I am searching. I want the changes to occur in another file, new or existing. How do I make this happen? Or is this method completely off.
Oh and by the way, this expression takes something like this in the html file:
Title of Link
and turns it into this in the xml file:
<title>Title of Link</title>
<link>http://linktosomesite.com</link>
<description>Description of link</description>
Bonus: It would be really nice if I can place this within another file, say starting at line 5.
PS: I know this is a vim and regex question but posting it in html and rss because I noticed people have static html to rss questions there.
Why not just copy your file and then use sed/replace on the copied file?
It sounds like you want to write a transform. There are many transform tools. You certainly could do it with sed & awk for example. But I think the easiest way would be xslt. (you could use xsltproc or saxon...)
Here's an example template:
<xsl:template match="a">
<title><xsl:value-of select="text()"/></title>
<link><xsl:value-of select="#href"/></link>
<description><xsl:value-of select="#title"/></description>
</xsl:template>
It finds each a element, and outputs the results, with the text() node and attributes filled in.
Just run your substitution and save as another file:
$ vim file.html
:%s/^<a href="\(.\{-}\)".title="\(.\{-}\)">\(.\{-}\)<\/a>/<title>\3<\/title>\r<link>\1<\/link>\r<description>\2<\/description>
:w file.rss
:q
That's how I would in any editor, by the way.

How to display source code with indent in a web page? HTML? CSS?

I want to show some source code with the WebBrowser control on a winform. And I want to decorate the source code with HTML tags, such as color, font, and size. But I found it difficult to display the indent properly.
To be precise, my source code are held in String[], and each String holds the proper indent (space or tab) already. But it seems these kinds of indent are just ignored by the WebBrowser control.
Could someone tell me how to?
I like to paste my code in a Gist and then display it that way. Github will recognize the code and format it accordingly.
If you're going to be doing it often you could try markdown.
Or use a one-off formatter like Syntax Highlighter.
The <pre> element (using <code> elements with appropriate class names to mark up the parts you want to syntax highlight)
<pre><code class="javascript"><code class="keyword">function</code> <code class="name">foo</code>()…
You might want to look into this JavaScript library to highlight and format your code. http://code.google.com/p/syntaxhighlighter/
Or you can check out a service like this - http://pygments.appspot.com/ or this - http://hilite.me/

HTML without “self-closing” tags

There's some way to cut the html tags with self-closing slash like <br/> and transform it to <br> so you can view on the source view the code without the slash?
Some DOM Jquery implementation?
I'm working on .NET if this can be help as a tip.
This is the real problem: NET-enabling start-tag requires SHORTTAG YES
In your other question, DaveB's answer points to a browser capabilities file. In that file the tagWriter is set toSystem.Web.UI.HtmlTextWriter.
I haven't tested this, but you may be able to sub-class System.Web.UI.HtmlTextWriter and initialse the value of the SelfClosingTagEnd field so that its value is > instead of />.
Put the name of the new class in the tagWriter setting of your browser capabilities file and try that.