HTML Help, need easy way to change text on my site - html

i am making a website that will feature many articles that will always be changing, i am trying to find a way to quickly change the text in these articles as i am the only person who knows the code in the company.
I was thinking of having a text document or something that has the articles text and when it gets changed so does the text on the site.I just dont know how to implement this.
sorry if its hard to understand what i mean, im not too familiar with sleep these days.

You don't need any dynamic server code like the other answers are suggesting. Either a "static site generator" (there are uncountably many, but that should give you something to Google if my main answer doesn't satisfy you) or a client-side scripting.
XSLT was designed for this exact problem. It can be run client-side or server-side with xsltproc (for compatibility with dumb clients). XSLT 1.0 is well-supported by all common browsers, though if you need EXSLT extensions in IE you had to add shims. Note that Webkit-based browsers can't do XSLT on file:// URLs, either set up a local HTTP server or use Firefox.
I have a minimal example site set up here that includes multiple files in
one page: https://o11c.github.io/foo-test/foo-root.xml
foo-style.xml:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/index">
<html>
<body>
<h2>Merge test</h2>
<table border="1">
<tr>
<th>Attr</th>
<th>Value</th>
</tr>
<xsl:apply-templates select="document(include/#name)"/>
</table>
</body>
</html>
</xsl:template>
<xsl:template match="root">
<xsl:for-each select="foo">
<tr>
<td><xsl:value-of select="#x"/></td>
<td><xsl:value-of select="text()"/></td>
</tr>
</xsl:for-each>
</xsl:template>
<xsl:template name="identity">
<xsl:copy>
<xsl:for-each select="node()|#*">
<xsl:call-template name="identity"/>
</xsl:for-each>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
foo-root.xml:
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="foo-style.xslt"?>
<index>
<include name="foo-1.xml"/>
<include name="foo-2.xml"/>
</index>
foo-1.xml:
<?xml version="1.0"?>
<root>
<foo x="a">aa</foo>
<foo x="b">bb</foo>
<foo x="c">cc</foo>
</root>
foo-2.xml:
<?xml version="1.0"?>
<root>
<foo x="d">dd</foo>
<foo x="e">ee</foo>
<foo x="f">ff</foo>
</root>
Further resources:
XSLT 1.0 spec
XPath 1.0 spec - in particular the function reference
EXSLT extensions - node-set in particular is very useful.
xsltproc webpage

You could use wordpress, if you are building the site from scratch and not adding to an existing one. This will allow you to edit articles in a user friendly interface that will allow you to style the text and will be easier for other people in the company to edit as well. It's very fast to set up.
Or you could just keep the written text in the HTML file itself, but this may make it harder to maintain and style, and those not technical savvy may not be able to edit it or will end up breaking it.

Well you might do this using php and Mysql
You can easily display save the articles in mysql and you could create a simple user interface for the people respnsible for editing the code to edit it too easy

Related

adding CSS styling to the <xsl:element name="standard_element_name">

As per SO standards, I have researched this question in Google and Yahoo, and on W3Schools and other forums for hours before posting here.
All answers I have found so far are geared towards specialized XML languages and other application that are going to read the XML file.
I am not doing this, nor am I writing any other type of code (such as C++, Java, C#, etc; nor am I wanting to use JavaScript).
The small local site I am creating is using only files in HTML, XML, and XSL, and a hand full of image files stored as .jpg and png. There is nothing else.
My little site is running on a local PC based Windows 10 computer with IIS enabled. The site works and other computers can view it in the common web browsers (such as FireFox and Chrome) through the LAN.
The only issue is my coding.
My project is to create a very basic, static site with simple HTML to the output, using nothing but XML and XSLT.
I have an XSL file which defines all of the standard HTML tags in templates [such as (p) (div) (table) (tr) (th) (td), etc] I also have many custom tags, which is why I want to use XML.)
I have reached a point where I want to use the (xsl:element name=" "). For example, I want to define a typical HTML (p style="color:yellow;"), using the (xsl:element name="p").
Here is a small sample of xsl I already have:
<xsl:element name="p">
<xsl:value-of select="p" />
</xsl:element>
This works, and a very plain (p) tag is created in the output and all the text is displayed. But, it has no styling. In the browser output it looks like this
<p>
A paragraph of text in here.
</p>
Having explained the above, my question is (hoping to be very clear), how to do I use the (xsl: element name="p") as shown above to add style attributes to it so my HTML output looks something like this:
<p style="background-color:yellow; font-size: 16pt;">
A paragraph of text in here, which is now black on a yellow background and a 16 point font.
</p>
I have answered my own question, and have included my complete, actual XSLT and some of my XML file for others that may be struggling with this. The short answer is the (xsl:attribute name="style") that is directly below the (xsl:element name="div").
I have included the complete code, which creates a (div) in the output on the left side that remains in a fixed position (meaning it does not scroll). This is a space for a list of links to other chapters used as a menu. The short piece of code beginning with the (xsl:element name="div") and ending with the closing tag (/xsl:element) creates that area, and the (for-each) block reads all the (list-text) and (url) tags [children of the (side_menu_div) tag, then creates a list of links in the (div) area on the side.
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="ROOT">
<html>
<head>
<xsl:element name="title">
<xsl:value-of select="title" />
</xsl:element>
</head>
<body style="background-color:#fffc99;">
<xsl:element name="div">
<xsl:attribute name="style">width: 10%; height: 100%; position: fixed; padding-right: 1em; background: white</xsl:attribute>
<xsl:for-each select="/ROOT/side_menu_div/link-text">
<xsl:variable name="index" select="position()" />
<a href="{/ROOT/side_menu_div/url[$index]}">
<xsl:value-of select="." />
</a>
<br/>
</xsl:for-each>
</xsl:element>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
The actual XML
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="/style-sheets/master.xsl"?>
<ROOT>
<title>Player's Core Rulebook</title>
<side_menu_div>
<link-text>Home Menu</link-text>
<url>/methasia_index.html</url>
<br></br>
<link-text>Preamble</link-text>
<url>/rulebooks/_players_core_rulebook/00-Preamble/Preamble.xml</url>
<link-text>Chapter 1</link-text>
<url>/rulebooks/_players_core_rulebook/01-Chapter-01/chapter_1.xml</url>
<link-text>Chapter 2</link-text>
<url>/rulebooks/_players_core_rulebook/02-Chapter-02/chapter_2.xml</url>
<link-text>Chapter 3</link-text>
<url>/rulebooks/_players_core_rulebook/03-Chapter-03/chapter_3.xml</url>
<link-text>Chapter 4</link-text>
<url>/rulebooks/_players_core_rulebook/04-Chapter-04/chapter_4.xml</url>
<link-text>Chapter 5</link-text>
<url>/rulebooks/_players_core_rulebook/05-Chapter-05/chapter_5.xml</url>
<link-text>Chapter 6</link-text>
<url>/rulebooks/_players_core_rulebook/06-Chapter-06/chapter_6.xml</url>
<link-text>Chapter 7</link-text>
<url>/rulebooks/_players_core_rulebook/07-Chapter-07/chapter_7.xml</url>
<link-text>Chapter 8</link-text>
<url>/rulebooks/_players_core_rulebook/08-Chapter-08/chapter_8.xml</url>
<link-text>Chapter 9</link-text>
<url>/rulebooks/_players_core_rulebook/09-Chapter-09/chapter_9.xml</url>
<link-text>Chapter 10</link-text>
<url>/rulebooks/_players_core_rulebook/10-Chapter-10/chapter_10.xml</url>
<link-text>Appendix</link-text>
<url>/rulebooks/_players_core_rulebook/11-Appendix/Players_Core_Rulebook_Appendix.xml</url>
</side_menu_div>

Concatenate two xml/html Files with XSLT

i'm trying to concatenate two Files. One of them XML and the other HTML. I'm probably making a stupid mistake, i'm not very familiar with handling XSLT.
I apply an XSL file to a XML file that looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<REPORT>
<YASCA />
<AOSCAT />
</REPORT>
And this is what the XSL file looks like:
<?xml version="1.0"?>
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml"/>
<xsl:template match="//YASCA">
<xsl:copy>
<xsl:copy-of select="document('abc.xml')"/>
</xsl:copy>
</xsl:template>
<xsl:template match="//AOSCAT">
<xsl:copy>
<xsl:copy-of select="document('xyz.html')"/>
</xsl:copy>
</xsl:template>
</xsl:transform>
And this is the error-message i get from AltovaXMLSpy after applying the XSLT and trying to save the created document:
XML Production Error: Character 'A' following the text '<' does not fulfill production 'Misc'.
It occurs at the point in the file where the first tag (the container for the contents of the XML file) ends and the second one (the container for the contents of the HTML file) starts.
</YASCA><AOSCAT>
I also tried different approaches of combining the files (some of them i found on stackoverflow), but none of them worked and this seems to be the most favorable since it's simple should does exactly what i want.
I hope i sufficiently explained my Problem and someone can help me.
Best regards
Marty
Well in general HTML is not XML and you won't be able to use document('file.html') sucessfully. But in your case it seems that operation works but you failed to ensure your root element is copied, so you end up with two top level elements in the result document which is then not XML as there needs to be a single root element. So add
<xsl:template match="/*">
<xsl:copy>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
in your XSLT and the result will be a well-formed XML document with a single root element.
That rather cryptic error message basically tells you that the markup following the first result element does not match the Misc production in the XML specification which only allows comments and/or processing instructions following the single allowed root element.

XSLT disable-ouput-escaping not escaping character <

In the following stylesheet:
<?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>
<h1>Music Collection:</h1>
<table border="1">
<tr bgcolor="#9acd32">
<th>Title</th>
<th>Artist</th>
</tr>
<tr>
<td><xsl:value-of select="catalog/cd/title" disable-output-escaping="yes" /></td>
<td><xsl:value-of select="catalog/cd/artist" /></td>
</tr>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Why does it not convert the < to < when used with the following HTML?
<?xml version="1.0" encoding="ISO-8859-1"?>
<!-- Edited by XMLSpy® -->
<catalog>
<cd>
<title>Empire Burlesque < </title>
<artist>Bob Dylan</artist>
<country>USA</country>
<company>Columbia </company>
<price>10.90</price>
<year>1985</year>
</cd>
</catalog>
The output can be tested here.. http://www.w3schools.com/xsl/tryxslt.asp?xmlfile=cdcatalog&xsltfile=tryxsl_value-of
Edit
Here is another example where it does not work
<xsl:for-each select="//productType">
<xsl:value-of select="." disable-output-escaping="yes" />
<br></br>
</xsl:for-each>
With the DOE the < get stripped out. Without it i can see the < character (Using XSLT 1.0)
disable-output-encoding was an optional feature in XSLT 1 (and is deprecated in XSLT 2) so a processor is allowed to ignore it. In particular it is almost always ignored in any processing pipeline in which the output from XSLT is passed as an in-memory tree (a DOM node for example) to a following application which then serialises the XML. d-o-e is essentially a hint to the XSLT serialisation phase and in such a processing pipeline XSLT serialisation is not used.
It is something processor-related (a bug I'd say) - using the .NET XSLT processor in Visual Studio I get < as expected, and I get < if I remove disable-output-escaping="yes"
The effect of disable-output-escaping depends on what processor you are using and on the way in which you are using it. You haven't given us enough information to answer these questions.
More pertinently, why are you using it? What problem are you trying to solve? Usually, when people use disable-output-escaping, they are going about things the wrong way - there's a better approach available. There are some cases where d-o-e is appropriate, but it means you can only use the stylesheet with a processor that supports it, in a pipeline where you know that the stylesheet's result tree is being piped straight into a serializer rather than into some other tree-consuming process.

How do I inline the contents of an external HTML document using XSLT?

I have an XSLT that I input to a 3rd party application. This application displays the result of that XSLT as a web page in their application.
I have a dynamic HTML document that I want to display in that application. How can I "read" the HTML document via an XSLT document such that whenever the html document is updated, the XSLT will read the new file?
If I'm not being clear, to convey the idea, my xslt would read something like this:
<xsl:stylesheet>
<xsl:output method="html"/>
<xsl:template match="Something">
<!-- Stuff is done here -->
</xsl:template>
<xsl:ReadExternalDocument filePath="my/path/document.html" />
</xsl:stylesheet>
I've come across the Document() function, but it seems to destroy my tags. That is, I would like to include the child tags of the parent element in the output.
As Tomalak suggested, the document function is the way to go. I read in the external HTML document using the document() with the copy-of node. copy-of does a deep-copy, including tags, to obtain the whole external HTML document. The code looks like this:
<xsl:stylesheet ... >
<xsl:output method="html"/>
<xsl:template match="/">
<xsl:copy-of select="document('ExternalDocument.html')" />
</xsl:template>
</xsl:stylesheet>

Transforming HTML with XSL and modifying form attributes

I would like to parse HTML document and replace action attribute of all the forms and add some hidden fields with XSL. Can someone show some examples of XSL that can do this?
What you need first is well formed HTML (at least transitional), although best recommended XHTML. Some XSLT processors could accept malformed HTML but it is not the rule.
To try the example below you can download this small Microsoft command line app.
Quick and dirty XSLT example for what you need (example-xslt.xsl):
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="*">
<xsl:copy>
<xsl:copy-of select="#*"/>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
<xsl:template match="form[#action='foo']">
<xsl:copy>
<xsl:copy-of select="#*"/>
<xsl:attribute name="action">non-foo</xsl:attribute>
<input type="hidden" name="my-hidden-prop" value="hide-foo-here"/>
<xsl:apply-templates select="*"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
And the corresponding XML example (example.xml).
<?xml version ="1.0"?>
<?xml-stylesheet type="text/xsl" href="example-xslt.xsl"?>
<html>
<head></head>
<body>
<form action="foo">
</form>
<form action="other">
</form>
</body>
</html>
Thinking of gurin's answer: one possible XSLT-based pathway for HTML is to use tidy to convert it to XHTML, apply XSLT to the XHTML, but use xsl:output[#method="html"] to get HTML back out. The #doctype-system and #doctype-public attributes let you provide a doctype declaration in the output file as well.
I don't have any sample files for shahbhat, but the general approach is straightforward from an XSLT point of view: start with an identity transform and add in templates for the action attributes to override them in the way you want. To add hidden fields, I suspect the easiest way would be to create a template explicitly for the form element as an identity transform, but with additional elements inside it that are output as well. I think Fernando Miguélez has just posted an example.
You can start from this tutorial
But be aware that generally XSLT requires well-formed XML as input and HTML isn't always well-formed