XSLT validation error javax.xml.transform.TransformerConfigurationException: - xslt

i'm having this error when i tried to validate my XSLT
javax.xml.transform.TransformerConfigurationException:
javax.xml.transform.TransformerException:
javax.xml.transform.TransformerException:
A node test that matches either NCName:* or QName was expected.
this is my XSLT
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:output method="html" />
<xsl:template match="\Apps">
<html>
<head> <title>Apps List</title>
<link rel="StyleSheet" href="table_style.css" type="text/css"/>
<style type="text/css">
body {font-family: Helvetca;}
h1 { color : Grey;}
h2 {color : Blue;}</style>
</head>
<body>
<h1> Apps List: <xsl:value-of select="\#List_Type" /></h1>
<p>This is a list of all currently hot apps:</p>
<xsl:for-each select="\App">
<xsl:if test="\App\#installed == true">
<h2 style="color:Green;"><xsl:value-of select="\App\app_name" />(instaled)</h2>
</xsl:if>
<xsl:otherwise>
<h2><xsl:value-of select="\App\app_name" /></h2>
</xsl:otherwise>
<p style="font-style:bold;">App info:</p>
<table id="#gradient-style">
<tr><th>Category:</th><td><xsl:value-of select="\App\catogry" /></td></tr>
<tr><th>Verdion:</th><td><xsl:value-of select="\App\version" /></td></tr>
<tr><th>Description:</th><td><xsl:value-of select="\App\description" /></td></tr>
<tr><th>App Reviews:</th><td><xsl:for-each select="\App\reviews\review">
<span style="font-style:bold;"><xsl:value-of select="\App\reviews\review\reviewer_name" /></span>
| <xsl:value-of select="\App\reviews\review\review_date" />
| <xsl:value-of select="\App\reviews\review\review_Time" /><br/>
<span style="font-style:bold;">Rating:</span>
<xsl:value-of select="string(\App\reviews\review\rating" /> <br/>
<xsl:value-of select="\App\reviews\review\ontent" /><br/>
----------------------------------------------------------
</xsl:for-each>
</td></tr>
</table>
</xsl:for-each>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
this is the XML that tried with
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="ShdenXSLT.xsl"?>
<Apps xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance" List_Type="new releases" >
<App device_type="tablet" app_id="120">
<app_name>Meeting Manager</app_name>
<catogry>LifeStyle </catogry>
<catogry>Bussnisse </catogry>
<version>1.0</version>
<description>This app is about managing the bussnisse meeting</description>
<reviews>
<review>
<reviewer_name>Shaden</reviewer_name>
<review_date>2012-02-13</review_date>
<review_time>11:35:02</review_time>
<content>it was a useful app</content>
<rating>4.5</rating>
</review>
<review>
<reviewer_name>Mohamed</reviewer_name>
<review_date>2012-03-01</review_date>
<review_time>12:15:00</review_time>
<content>i really loved this app</content>
<rating>5.0</rating>
</review>
</reviews>
</App>
<App device_type="tablet" app_id="100">
<app_name>ToDoList</app_name>
<catogry>LifeStyle </catogry>
<version>3.4.2</version>
<description>a simple To Do List applecation</description>
<reviews>
<review>
<reviewer_name>Fahad</reviewer_name>
<review_date>2010-02-05</review_date>
<review_time>09:40:55</review_time>
<content>nice app</content>
<rating>4.0</rating>
</review>
</reviews>
</App>
</Apps>

You are using backslash (\) as your XPath separator (i.e. <xsl:value-of select="\#List_Type" />), which is incorrect. It should be a forward slash (/)

Related

To assign dynamic URL's

I am new to XSLT Language, I am trying to write code that assigns dynamic URL's to Photo field in my list. My list contains FirstName, LastName and Photo fields of all employees and Photos are in a folder ("file://folder/subfolder/LastName, FirstName.jpg). Based on FirstName and LastName appropriate photo should be dynamically added to Photo Field.
Code I tried:
<xsl:template match="udt:Photo">
<xsl:for-each select="dnnGridItem">
<xsl:value-of select="udt:LastName" />
<xsl:value-of select="udt:FirstName" />
</xsl:for-each>
<img border="0" alt="delete">
<xsl:attribute name="src">
<xsl:text>file://folder/subfolder</xsl:text>
<xsl:value-of select="file://foilder/subfoilder/?{LastName}, {FirstName}.jpg" />
<xsl:text>.jpg</xsl:text>
</xsl:attribute>
</img>
</xsl:template>
Can any one help me with XSL code.
As you did not provide any input data I can suggest my example.
In my case required images are in path D:/images as below:
So to add images to HTML I am using next XSL file (photo.xsl) as below:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="html" />
<xsl:template match="/Photo">
<xsl:variable name="img.path" select="'file:///D:/images/'"/>
<html>
<body>
<xsl:for-each select="dnnGridItem">
<xsl:variable name="img.name" select="concat(LastName, ', ', FirstName)"/>
<h2>
<xsl:value-of select="$img.name"/>
</h2>
<img border="0" alt="delete">
<xsl:attribute name="src">
<xsl:value-of select="concat($img.path, $img.name, '.jpg')"/>
</xsl:attribute>
</img>
<br/>
</xsl:for-each>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Then to take LastName and FirstName dynamically add <?xml-stylesheet type="text/xsl" href="photo.xsl"?> to input XML file (input.xml) as below:
<?xml-stylesheet type="text/xsl" href="photo.xsl"?>
<Photo>
<dnnGridItem>
<FirstName>John</FirstName>
<LastName>Smith</LastName>
</dnnGridItem>
<dnnGridItem>
<FirstName>Kate</FirstName>
<LastName>Johnson</LastName>
</dnnGridItem>
</Photo>
Result:
Transformed result:
<html>
<body>
<h2>Smith, John</h2>
<img border="0" alt="delete" src="file:///D:/images/Smith, John.jpg"><br>
<h2>Johnson, Kate</h2>
<img border="0" alt="delete" src="file:///D:/images/Johnson, Kate.jpg"><br>
</body>
</html>
Result when open XML(input.xml) file in browser:
NOTE! input.xml - in same folder with photo.xsl.
Hope it will help with your case.

Unable to understand why a template match is not caught though declared

I'm writing a XSLT script and there is a section named footnotes, my script is catching all elements other than footnotes. I'm using XSL2.0 and Below is my XML
<?xml version="1.0" encoding="utf-8"?>
<chapter num="D" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:acknowledgement="file://acknowledgement.xsd" xmlns:admission="file://admission.xsd" xmlns:affidavit="file://affidavit.xsd" xmlns:agreement="file://agreement.xsd" xmlns:appeal="file://appeal.xsd" xmlns:appearance="file://appearance.xsd" xmlns:application="file://application.xsd" xmlns:assent="file://assent.xsd" xmlns:authorisation="file://authorisation.xsd" xmlns:award="file://award.xsd" xmlns:brief="file://brief.xsd" xmlns:caveat="file://caveat.xsd" xmlns:certificate="file://certificate.xsd" xmlns:checklist="file://checklist.xsd" xmlns:claim="file://claim.xsd" xmlns:clause="file://clause.xsd" xmlns:comparisontable="file://comparisontable.xsd" xmlns:conditionsofcontract="file://conditionsofcontract.xsd" xmlns:declaration="file://declaration.xsd" xmlns:defaultjudgment="file://defaultjudgment.xsd" xmlns:defence="file://defence.xsd" xmlns:demand="file://demand.xsd" xmlns:flowchart="file://flowchart.xsd" xmlns:form="file://form.xsd" xmlns:guarantee="file://guarantee.xsd" xmlns:instruction="file://instruction.xsd" xmlns:judgment="file://judgment.xsd" xmlns:letter="file://letter.xsd" xmlns:minutes="file://minutes.xsd" xmlns:notice="file://notice.xsd" xmlns:oath="file://oath.xsd" xmlns:order="file://order.xsd" xmlns:patent="file://patent.xsd" xmlns:petition="file://petition.xsd" xmlns:powerofattorney="file://powerofattorney.xsd" xmlns:praecipe="file://praecipe.xsd" xmlns:questionnaire="file://questionnaire.xsd" xmlns:recognisance="file://recognisance.xsd" xmlns:release="file://release.xsd" xmlns:renunciation="file://renunciation.xsd" xmlns:reply="file://reply.xsd" xmlns:report="file://report.xsd" xmlns:request="file://request.xsd" xmlns:schedule="file://schedule.xsd" xmlns:statementofclaim="file://statementofclaim.xsd" xmlns:subpoena="file://subpoena.xsd" xmlns:summons="file://summons.xsd" xmlns:undertaking="file://undertaking.xsd" xmlns:warrant="file://warrant.xsd" xmlns:writ="file://writ.xsd" xmlns:book="file://book.xsd" xmlns:forms="file://forms.xsd" xmlns:misc="file://misc.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:htm="http://www.w3.org/TR/html5/">
<htm:p align="center">
<htm:b>Bold Content</htm:b>
<footnote num="1">
<para>
Footnote content.
</para>
</footnote>
</htm:p>
</chapter>
And below is my XSLT.
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ntw="Number2Word.uri" xmlns:altova="http://www.altova.com/xslt-extensions" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:acknowledgement="file://acknowledgement.xsd" xmlns:admission="file://admission.xsd" xmlns:affidavit="file://affidavit.xsd" xmlns:agreement="file://agreement.xsd" xmlns:appeal="file://appeal.xsd" xmlns:appearance="file://appearance.xsd" xmlns:application="file://application.xsd" xmlns:assent="file://assent.xsd" xmlns:authorisation="file://authorisation.xsd" xmlns:award="file://award.xsd" xmlns:brief="file://brief.xsd" xmlns:caveat="file://caveat.xsd" xmlns:certificate="file://certificate.xsd" xmlns:checklist="file://checklist.xsd" xmlns:claim="file://claim.xsd" xmlns:clause="file://clause.xsd" xmlns:comparisontable="file://comparisontable.xsd" xmlns:conditionsofcontract="file://conditionsofcontract.xsd" xmlns:declaration="file://declaration.xsd" xmlns:defaultjudgment="file://defaultjudgment.xsd" xmlns:defence="file://defence.xsd" xmlns:demand="file://demand.xsd" xmlns:flowchart="file://flowchart.xsd" xmlns:form="file://form.xsd" xmlns:guarantee="file://guarantee.xsd" xmlns:instruction="file://instruction.xsd" xmlns:judgment="file://judgment.xsd" xmlns:letter="file://letter.xsd" xmlns:minutes="file://minutes.xsd" xmlns:notice="file://notice.xsd" xmlns:oath="file://oath.xsd" xmlns:order="file://order.xsd" xmlns:patent="file://patent.xsd" xmlns:petition="file://petition.xsd" xmlns:powerofattorney="file://powerofattorney.xsd" xmlns:praecipe="file://praecipe.xsd" xmlns:questionnaire="file://questionnaire.xsd" xmlns:recognisance="file://recognisance.xsd" xmlns:release="file://release.xsd" xmlns:renunciation="file://renunciation.xsd" xmlns:reply="file://reply.xsd" xmlns:report="file://report.xsd" xmlns:request="file://request.xsd" xmlns:schedule="file://schedule.xsd" xmlns:statementofclaim="file://statementofclaim.xsd" xmlns:subpoena="file://subpoena.xsd" xmlns:summons="file://summons.xsd" xmlns:undertaking="file://undertaking.xsd" xmlns:warrant="file://warrant.xsd" xmlns:writ="file://writ.xsd" xmlns:book="file://book.xsd" xmlns:forms="file://forms.xsd" xmlns:misc="file://misc.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:htm="http://www.w3.org/TR/html5/" xpath-default-namespace="http://foo.bar.com/ns" exclude-result-prefixes="#all">
<xsl:output method="html"/>
<xsl:strip-space elements="*"/>
<!--<xsl:preserve-space elements="para"/>-->
<xsl:variable name="nums" as="element()+">
<ntw:nums num="1" word="first"/>
<ntw:nums num="2" word="second"/>
<ntw:nums num="3" word="third"/>
<ntw:nums num="4" word="forth"/>
<ntw:nums num="5" word="fifth"/>
<ntw:nums num="6" word="sixth"/>
<ntw:nums num="7" word="seventh"/>
<ntw:nums num="8" word="eighth"/>
<ntw:nums num="9" word="nighth"/>
<ntw:nums num="10" word="tenth"/>
</xsl:variable>
<xsl:template match="/">
<xsl:text disable-output-escaping="yes"><![CDATA[<!DOCTYPE html>]]></xsl:text>
<html>
<head>
<xsl:text disable-output-escaping="yes"><![CDATA[</meta>]]></xsl:text>
<title>
<xsl:value-of select="chapter/title/text()"/>
</title>
<link rel="stylesheet" href="C:\Users\u0138039\Desktop\Proview\MY\2016\CCA3ED\XML\XSLT\main.css" type="text/css"/>
<xsl:text disable-output-escaping="yes"><![CDATA[</link>]]></xsl:text>
</head>
<body>
<section class="tr_chapter">
<xsl:apply-templates/>
</section>
<xsl:if test="//footnote">
<section class="tr_footnotes">
<xsl:text disable-output-escaping="yes"><![CDATA[<hr />]]></xsl:text>
<xsl:apply-templates select="//page | //footnote" mode="footnote"/>
</section>
</xsl:if>
</body>
</html>
</xsl:template>
<xsl:template match="chapter">
<xsl:apply-templates select="descendant::title[1]/page" mode="first"/>
<div class="chapter">
<xsl:variable name="num_S">
<xsl:value-of select="."/>
</xsl:variable>
<a name="CLIHK_CH_{$num_S}"/>
<div class="chapter-title">
<span class="chapter-num">
<xsl:value-of select="normalize-space(concat('Chapter ',format-number(./#num,'0')))"/>
</span>
<xsl:text disable-output-escaping="yes"><![CDATA[<br /><br />]]></xsl:text>
<xsl:apply-templates select="title/node() except descendant-or-self::page"/>
<xsl:text disable-output-escaping="yes"><![CDATA[<br /><br />]]></xsl:text>
<xsl:apply-templates select="chapter-meta"/>
</div>
<xsl:apply-templates select="child::node()[not(self::title|self::chapter-meta)]"/>
</div>
</xsl:template>
<xsl:template match="htm:b">
<span class="font-style-bold">
<xsl:apply-templates/>
</span>
</xsl:template>
<xsl:template match="htm:p">
<xsl:apply-templates select="./node()[1][self::page]" mode="first"/>
<div>
<xsl:choose>
<xsl:when test="./#align">
<xsl:attribute name="class"><xsl:text>para align-</xsl:text><xsl:value-of select="./#align"/></xsl:attribute>
</xsl:when>
<xsl:otherwise>
<xsl:attribute name="class"><xsl:text>para</xsl:text></xsl:attribute>
</xsl:otherwise>
</xsl:choose>
<xsl:apply-templates/>
</div>
</xsl:template>
<xsl:template match="footnote">
<xsl:variable name="cnt" select="count(preceding::footnote)+1"/>
<xsl:variable name="varHeaderNote" select='concat("f",$cnt)'/>
<xsl:variable name="varFootNote" select='concat("#ftn.",$cnt)'/>
<sup>
<a name="{$varHeaderNote}" href="{$varFootNote}" class="tr_ftn">
<xsl:value-of select="#num"/>
</a>
</sup>
</xsl:template>
<xsl:template match="footnote" mode="footnote">
<xsl:variable name="cnt" select="count(preceding::footnote)+1"/>
<div class="tr_footnote">
<div class="footnote">
<sup>
<a>
<xsl:attribute name="name"><xsl:text>ftn.</xsl:text><xsl:value-of select="$cnt"/></xsl:attribute>
<xsl:attribute name="href"><xsl:text>#f</xsl:text><xsl:value-of select="$cnt"/></xsl:attribute>
<xsl:attribute name="class"><xsl:text>tr_ftn</xsl:text></xsl:attribute>
<xsl:value-of select="#num"/>
</a>
</sup>
<xsl:apply-templates/>
</div>
</div>
</xsl:template>
</xsl:stylesheet>
My current output is as below
<!DOCTYPE html><html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"></meta>
<title></title>
<link rel="stylesheet" href="C:\Users\u0138039\Desktop\Proview\MY\2016\CCA3ED\XML\XSLT\main.css" type="text/css"></link>
</head>
<body>
<section class="tr_chapter">
<div class="para align-center"><span class="font-style-bold">Bold Content</span>
Footnote content.
</div>
</section>
</body>
</html>
But my expected output is
<!DOCTYPE html><html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"></meta>
<title></title>
<link rel="stylesheet" href="C:\Users\u0138039\Desktop\Proview\MY\2016\CCA3ED\XML\XSLT\main.css" type="text/css"></link>
</head>
<body>
<section class="tr_chapter">
<div class="para align-center"><span class="font-style-bold">Bold Content</span><sup>
<a name="f1" href="#ftn.1" class="tr_ftn">1</a>
</sup>
</div>
</section>
<section class="tr_footnotes"><hr/>
<div class="tr_footnote">
<div class="footnote">
<sup>
<a name="ftn.1" href="#f1" class="tr_ftn">1</a>
</sup>
<div class="para">Footnote content.
</div>
</div>
</div></section>
</body>
</html>
Here is a working demo
please let me know where Am I going wrong and how can I fix this.
Thanks
Your stylesheet declares:
xpath-default-namespace="http://foo.bar.com/ns"
The footnote in your XML is in no namespace, therefore the test in:
<xsl:if test="//footnote">
returns false.

using XSLT to display image series with captions in XHTML

I'm trying to display a series of images each with its own caption using XSLT. I've coded the images and the captions by nesting <img> and then <figcaption> within but the resultant html does not display as intended (the captions are not lining up with corresponding images). Is there a way to nest <xsl: for-each> for the captions within the images? Here's the XSLT:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="xs"
version="2.0">
<xsl:output method="html"/>
<xsl:template match="letter">
<html>
<head>
<style type="text/css">
#wrapper {min-height: 100%;}
#figcaption {
text-align: left;
}
#main {
padding-top: 15px;;
width: 1200px;
}
</style>
</head>
<body>
<div id="wrapper">
<div id="images">
<figure>
<xsl:if test="image">
<xsl:for-each select="image/#xlink:href">
<img>
<xsl:attribute name="src">
<xsl:value-of select="."/>
</xsl:attribute>
</img>
</xsl:for-each>
</xsl:if>
<xsl:if test="image/#label">
<xsl:for-each select="image/#label">
<figcaption><xsl:value-of select="."/></figcaption>
</xsl:for-each>
</xsl:if>
</figure>
</div>
</div>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Here's the corresponding XML:
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="XSLT.xsl"?>
<letter xmlns:xlink="http://www.w3.org/1999/xlink">
<image label="page 1" xlink:href="http://tinyurl.com/nu7zmhc"/>
<image label="page 2" xlink:href="http://tinyurl.com/pysyztr"/>
<title>Letter from Shawn Schuyler</title>
<date>1963-06-30</date>
<language>English</language>
<creator>
<firstName>William</firstName>
<lastName>Schultz</lastName>
<street>Unites States Disciplinary Barracks</street>
<city>Fort Leavenworth</city>
<state abbr="KS">Kansas</state>
</creator>
</letter>
My desired output in html is basically this for each image:
<figure>
<img src='image.jpg'/>
<figcaption>Caption</figcaption>
</figure>
Or simply:
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xlink="http://www.w3.org/1999/xlink"
exclude-result-prefixes="xlink">
<xsl:template match="/letter">
<html>
<head>
<style type="text/css">
#wrapper {min-height: 100%;}
#figcaption {
text-align: left;
}
#main {
padding-top: 15px;;
width: 1200px;
}
</style>
</head>
<body>
<div id="wrapper">
<div id="images">
<xsl:for-each select="image">
<figure>
<img src='{#xlink:href}'/>
<figcaption>
<xsl:value-of select="#label"/>
</figcaption>
</figure>
</xsl:for-each>
</div>
</div>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Note:
There's nothing wrong with using xsl:for-each, especially in a
simple case like this;
There is something wrong with using xsl:element when you can use a literal result element. And while XSLT is naturally verbose, using the attribute value template can reduce the code (quite significanltly, as you can see in this case).
Try this:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="xs"
version="2.0">
<xsl:output method="html" indent="yes" />
<xsl:template match="letter">
<html>
<head>
<style type="text/css">
#wrapper {min-height: 100%;}
#figcaption {
text-align: left;
}
#main {
padding-top: 15px;;
width: 1200px;
}
</style>
</head>
<body>
<div id="wrapper">
<div id="images">
<xsl:apply-templates select="./image"></xsl:apply-templates>
</div>
</div>
</body>
</html>
</xsl:template>
<xsl:template match="letter/image">
<xsl:element name="figure">
<xsl:element name="img">
<xsl:attribute name="src">
<xsl:value-of select="./#xlink:href"/>
</xsl:attribute>
</xsl:element>
<xsl:apply-templates select="./#label"></xsl:apply-templates>
</xsl:element>
</xsl:template>
<xsl:template match="letter/image/#label">
<xsl:element name="figcaption">
<xsl:value-of select="."/>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
xsl:apply-templates says where anything matching the pattern specified in select should be put (with the dot showing the current element's context).
xsl:template is matched against the source document based on the path given in match. Any hits are processed in parallel, then later stitched together based on where the apply-templates elements indicate.
NB: depending on your XSLT engine having output="html" may have different effects on your img element. In HTML5 the img element is defined as not requiring a close tag (or being self-closing), so the engine won't close that tag. Arguments about whether that inconsistency is a good choice or not can be found throughout the net.
Ref: Are (non-void) self-closing tags valid in HTML5?
A good article on this alternate approach to for-each can be found here: http://gregbee.ch/blog/using-xsl-for-each-is-almost-always-wrong
You'll find with XLST that once the concept of a template clicks your code will become way shorter are simpler to maintain.

Build a tree from a XML file using XSLT?

Being a XML file, I know to generate some output by the XSL. But I need to build a navigation tree either to hidden the contents that I don't have to look at or show those I want to. Tree that I am looking for should look like this one:
+VIEW1
+VIEW2
if hitting something like '+' somewhere, for instance on VIEW2 , we should get the content of VIEW2 like this one:
+VIEW1
-VIEW2
yy NO
aa YES
zz NO
tt NO
Here's a part of my XML file and "view.xsl" which i wrote. I also tried to modify some examples from the stackoverflow but i didn't find how to get right solution.
view.xsl
<xsl:stylesheet version="2.0"
xmlns:xsl = "http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" cdata-section-elements="Cdata" indent="yes"/>
<xsl:template match = "/">
<html >
<head>
<title Localizable_1="True"><xsl:value-of select="DOC/show"/></title>
</head>
<BODY class="BODY">
<H1><xsl:value-of select="DOC/show"/></H1>
<TABLE WIDTH="500px">
<xsl:for-each select="DOC/Entry">
<xsl:call-template name="RULE"/>
</xsl:for-each>
</TABLE>
</BODY>
</html>
</xsl:template>
<xsl:template name="RULE">
<xsl:choose>
<xsl:if test="level='ON'"><xsl:value-of select="light"/>YES</xsl:if>
<xsl:if test="level='OFF'"><xsl:value-of select="light"/>NO</xsl:if>
</xsl:choose>
file.XML
<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml:stylesheet type='text/xsl' href='view.xsl'?>
<DOC>
<show>VIEW1</show>
<Entry>
<light>ae</light>
<level>ON</level>
</Entry>
<Entry>
<light>by</light>
<level>OFF</level>
</Entry>
<Entry>
<light>ac</light>
<level>OFF</level>
</Entry>
<show>VIEW2</show>
<Entry>
<light>yy</light>
<level>OFF</level>
</Entry>
<Entry>
<light>aa</light>
<level>ON</level>
</Entry>
<Entry>
<light>zz</light>
<level>OFF</level>
</Entry>
<Entry>
<light>tt</light>
<level>OFF</level>
</Entry>
</DOC>
Thanks for any help
This works (I build a table with tr and td elements but I assume you can enhance from here).
Helpful links on following-sibling
<xsl:stylesheet version="2.0"
xmlns:xsl = "http://www.w3.org/1999/XSL/Transform"
xmlns="http://www.w3.org/1999/xhtml" >
<xsl:output method="html" cdata-section-elements="Cdata" indent="yes"/>
<xsl:template match = "/">
<html >
<head>
<title Localizable_1="True">
<xsl:value-of select="DOC/show"/>
</title>
<script src="http://code.jquery.com/jquery-1.9.1.min.js" type="text/javascript">
<xsl:comment>jq</xsl:comment>
</script>
<script src="https://raw.github.com/vakata/jstree/master/dist/jstree.min.js" type="text/javascript">
<xsl:comment>tree</xsl:comment>
</script>
</head>
<body class="BODY">
<div class="tree">
<xsl:apply-templates select="DOC/show" />
</div>
<script>
$('div.tree')
.jstree({
core: {}
})
.bind("select_node.jstree", function (event, data) {
alert(data.node.context.id); /* do clever things here */
})
.delegate("a", "click", function (event, data) { event.preventDefault(); });
</script>
</body>
</html>
</xsl:template>
<!-- match show elements -->
<xsl:template match="show">
<ul class="tree">
<li>
<a>
<xsl:value-of select="."/>
</a>
<ul>
<!-- only select the next Entry element -->
<xsl:apply-templates select="following-sibling::*[1][self::Entry] "/>
</ul>
</li>
</ul>
</xsl:template>
<xsl:template match="Entry">
<li class="rule">
<xsl:call-template name="RULE"/>
</li>
<!-- only select the next Entry element -->
<xsl:apply-templates select="following-sibling::*[1][self::Entry] "/>
</xsl:template>
<xsl:template name="RULE">
<xsl:element name="a">
<!-- or have a href here -->
<xsl:attribute name="id">
<xsl:value-of select="light"/>
</xsl:attribute>
<span class="light">
<xsl:value-of select="light"/>
</span>
<span class="level">
<xsl:choose>
<xsl:when test="level='ON'">
<xsl:text>YES</xsl:text>
</xsl:when>
<xsl:when test="level='OFF'">
<xsl:text>NO</xsl:text>
</xsl:when>
</xsl:choose>
</span>
</xsl:element>
</xsl:template>
</xsl:stylesheet>

handling the data in the nested tags and grouping them in xslt

I need some clarification on XSLT how to do the following in XSLT.
I have the source file as this.
<Data>
<additem>
<choice>desc</choice>
<sectiontext>
<a title="google" href="http://google.com" xmlns="http://www.w3.org/1999/xhtml">
<strong>Sample Text</strong>
<ul>
<li><em>aa</em></li>
<li><em>bb</em></li>
<li><em>cc</em></li>
</ul>
</a>
</sectiontext>
</additem>
<additem>
<choice>image</choice>
<files>
<a xmlns="http://www.w3.org/1999/xhtml" title="image location" href="xyz:12-2022">
<img alt="No Image" title="No Image" xlink:href="some image path" xmlns:xlink="http://www.w3.org/1999/xlink"></img>
</a>
</files>
</additem>
<additem>
<choice>Paragraph</choice>
<sectiontext>
<a title="google" href="http://google.com" xmlns="http://www.w3.org/1999/xhtml">
<strong>Sample Text</strong>
<ul>
<li><em>aa</em></li>
<li><em>bb</em></li>
<li><em>cc</em></li>
</ul>
</a>
hello alll
</sectiontext>
</additem>
</Data>
Output:
<Information>
<Section>
<text>
<strong>Sample Text</strong>
<ul>
<li><em>aa</em></li>
<li><em>bb</em></li>
<li><em>cc</em></li>
</ul>
</text>
<link external="http://google.com" title="google"></link>
</Section>
<picture>
<image src="some image path" altText="No Image">
<link local="xyz:12-2022" title="image location"></link>
</image>
</picture>
<Body>
<text>
<hyperlink>
<text>
<strong>Sample Text</strong>
<ul>
<li><em>aa</em></li>
<li><em>bb</em></li>
<li><em>cc</em></li>
</ul>
</text>
<link external="http://google.com" title="google"></link>
</hyperlink>
hello alll
</text>
</Body>
</Information>
Rules:
1.Depending on the choice in addItem/choice, we need to create the tag.
choice -- Desc
desc -- Section
image -- picture
Paragraph----Body
2.Handling tag
Currently tag is wrapping for some other tag.
A.If any element has only <a> in it. For example in the source,
Code in the source:
<sectiontext>
<a title="google" href="http://google.com" xmlns="http://www.w3.org/1999/xhtml">
<strong>Sample Text</strong>
<ul>
<li><em>aa</em></li>
<li><em>bb</em></li>
<li><em>cc</em></li>
</ul>
</a>
</sectiontext>
Need to seperate that tag and create a tag
i. if the "href" in attribute in <a> tag starts with "xyz:" need to add it as "local" attribute in <link> element
ii. If the "href" in the attribute <a> tag starts with "http" need to add it as "external" attribute in <link> element.
ii. "title" attribute in <a> tag remains same in <link>
B.if any element has any other element other than <a> tag.
Code in the source:
<sectiontext>
<a title="google" href="http://google.com" xmlns="http://www.w3.org/1999/xhtml">
<strong>Sample Text</strong>
<ul>
<li><em>aa</em></li>
<li><em>bb</em></li>
<li><em>cc</em></li>
</ul>
</a>
hello alll
</sectiontext>
I need to get the out put as
<text>
<hyperlink>
<text>
<strong>Sample Text</strong>
<ul>
<li><em>aa</em></li>
<li><em>bb</em></li>
<li><em>cc</em></li>
</ul>
</text>
<link external="http://google.com" title="google"></link>
</hyperlink>
hello alll
</text>
Rules:
i. In the all the text inside the <a> tag have to come under the <inlinelink> tag as shown above.
Can any one help how it can be done.
Thank you.
This XSLT 1.0 style-sheet ...
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xhtml="http://www.w3.org/1999/xhtml"
xmlns:xlink="http://www.w3.org/1999/xlink" >
<xsl:output method="xml" indent="yes"/>
<xsl:template match="#*|node()">
<xsl:copy>
<xsl:apply-templates select="#*|node()" />
</xsl:copy>
</xsl:template>
<xsl:template match="/">
<Information>
<xsl:apply-templates select="Data/additem"/>
</Information>
</xsl:template>
<xsl:template match="xhtml:a[../../self::additem]">
<link title="{#title}">
<xsl:if test="starts-with(#href,'http')">
<xsl:attribute name="external"><xsl:value-of select="#href" /></xsl:attribute>
</xsl:if>
<xsl:if test="starts-with(#href,'xyz:')">
<xsl:attribute name="local"><xsl:value-of select="#href" /></xsl:attribute>
</xsl:if>
</link>
</xsl:template>
<xsl:template match="additem[choice='desc']">
<Section>
<text>
<xsl:apply-templates select="sectiontext/xhtml:a/*" />
</text>
<xsl:apply-templates select="sectiontext/xhtml:a" />
</Section>
</xsl:template>
<xsl:template match="additem[choice='image']">
<picture>
<image src="{files/xhtml:a/xhtml:img/#xlink:href}" altText="{files/xhtml:a/xhtml:img/#alt}">
<apply-templates select="files/xhtml:a" />
</image>
</picture>
</xsl:template>
<xsl:template match="additem[choice='Paragraph']">
<Body>
<text>
<hyperlink>
<text>
<xsl:apply-templates select="sectiontext/xhtml:a/*" />
</text>
<xsl:apply-templates select="sectiontext/xhtml:a" />
</hyperlink>
<xsl:apply-templates select="sectiontext/node()[not(self::xhtml:a)]" />
</text>
</Body>
</xsl:template>
</xsl:stylesheet>
... will transform your specified input document into this output document ...
<?xml version="1.0" encoding="utf-8"?>
<Information xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xlink="http://www.w3.org/1999/xlink">
<Section>
<text>
<strong xmlns="http://www.w3.org/1999/xhtml">Sample Text</strong>
<ul xmlns="http://www.w3.org/1999/xhtml">
<li><em>aa</em></li>
<li><em>bb</em></li>
<li><em>cc</em></li>
</ul>
</text>
<link title="google" external="http://google.com" />
</Section>
<picture>
<image src="some image path" altText="No Image">
<apply-templates select="files/xhtml:a" />
</image>
</picture>
<Body>
<text>
<hyperlink>
<text>
<strong xmlns="http://www.w3.org/1999/xhtml">Sample Text</strong>
<ul xmlns="http://www.w3.org/1999/xhtml">
<li><em>aa</em></li>
<li><em>bb</em></li>
<li><em>cc</em></li>
</ul>
</text>
<link title="google" external="http://google.com" />
</hyperlink>
hello alll
</text>
</Body>
</Information>
Explanation
Each of your rules was taken one by one and used to build a template, starting with the identification of the match condition.