i have my atom (list of continent as xml) at this url .../continent/search?view=atom like this:
<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:opensearch="http://a9.com/-/spec/opensearch/1.1/">
<title>List of all continents</title>
<opensearch:totalResults>{{ continents_length }}</opensearch:totalResults>
<opensearch:startIndex>{{ continents.start_index }}</opensearch:startIndex>
<opensearch:itemsPerPage>{{ count }}</opensearch:itemsPerPage>
<opensearch:Query continent="request" searchTerms="" startPage="{{ continents.start_index }}" />
<author><name>My_site</name></author>
<id>urn:domain-id:mysite.com:continent</id>
<link rel="self" href="{{ url }}" />
{% for continent in continents %}
<entry>
<span class="continent_id">{{ continent.continent_id }}</span>
<span class="continent_name">{{ continent.continent_name }}</span>
<span class="list_countries">{{ continent.list_countries }}</span>
</entry>
{% endfor %}
</feed>
When i want to PUT and index my feed in gsa-interface i have used this:
<?xml version="1.0" encoding="utf-8"?>
<entry xmlns="http://www.w3.org/2005/Atom">
<title>continent</title>
<id>urn:domain-id:mysite.com:continent</id>
<author>
<name>admin user</name>
</author>
<link rel="self" href=".../feed/continent"/>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<span id="refresh-each">15 12,14,18 * * *</span>
<span id="gsa-datasource">continent</span>
<span id="gsa-feedtype">full</span>
<span id="url">...continent/search?view=atom</span>
<span id="opensearch-pattern">&count=100&startPage=%STARTPAGE%</span>
<ul class="connection">
<li id="userid">user</li>
<li id="password">pass</li>
</ul>
<ul id="metadata">
<li id="continent_id">atom:entry/xhtml:span[#class='continent_id']</li>
<li id="continent_name">atom:entry/xhtml:span[#class='continent_name']</li>
<li id="list_countries">atom:entry/xhtml:span[#class='list_countries']</li>
</ul>
<div id="xsl-content">
<![CDATA[
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:xhtml="http://www.w3.org/1999/xhtml"
exclude-result-prefixes="atom xhtml">
<xsl:template name="FormatDescription">
<xsl:param name="name"/>
<xsl:value-of select="$name"/>
</xsl:template>
<xsl:template match="atom:entry">
<html>
<body>
<xsl:apply-templates select="atom:entry/xhtml:span" />
</body>
</html>
</xsl:template>
<xsl:template match="atom:entry/xhtml:span">
<xsl:copy-of select="*"/>
</xsl:template>
</xsl:stylesheet>
]]>
</div>
</div>
</content>
</entry>
But when i check the flux of transfered files it return 0 file with error:
ProcessNode: Missing required attribute url. skipping element., skipping record
For the second indexation and the tird one, there is no error, and neither no file !
200 OK Feed continent has been pushed successfully to the Google Search Appliance.
Any suggestion/recommandation ?
Following up on this, the word "feed" is confusing here. A GSA content feed is not like any RSS or Atom feeds. Here's a simplified example (from the documentation):
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE gsafeed PUBLIC "-//Google//DTD GSA Feeds//EN" "">
<gsafeed>
<header>
<datasource>hello</datasource>
<feedtype>incremental</feedtype>
</header>
<record url="http://www.corp.enterprise.com/hello02" mimetype="text/plain">
<content>UPDATED - This is hello02</content>
</record>
</group>
</gsafeed>
As you can see, that's a very specific XML format, not shared with web site update feed formats. The documentation for this is good: http://www.google.com/support/enterprise/static/gsa/docs/admin/70/gsa_doc_set/feedsguide/feedsguide.html
Check out the feed documentation
You need to pass the GSA a feed XML file, not an atom feed.
Related
I'm working on an XSLT script to create an ePub TOC from a source file. I am able to get the content I need for the HTML files themselves but I also need to include the <unit> and <chapter> tags as well. I'm stuck how to get those into my output file.
This is my input file:
<?xml version="1.0" encoding="UTF-8"?>
<toc xmlns="http://www.standardnine.com/s9ml" data-uuid="c667450f8f7d45888630f13533a20e14">
<metadata thumbnailpath="../img/toc_thumbs/.crops/9781506250953_7c4cbc8d37244424a9f2a00ab56b5db7.jpg">
<remarks path="remarks.s9ml"/>
<edition/>
<title>SHSAT Course 2021</title>
<author/>
<publisher/>
<shortname>sn_a9645</shortname>
<pubdate>Publish Date</pubdate>
<version>Version</version>
<revision>Revision</revision>
<s9version>s9version</s9version>
<productid>Product ID</productid>
<bundleconfig path="config.s9ml"/>
<reflowable>true</reflowable>
<subtitle/>
</metadata>
<spine>
<unit designation="" enumeration="" data-uuid="f2aab3845c9d4e1988de8c6a22429af8">
<title/>
<chapter thumbnailpath="../img/toc_thumbs/.crops/9781506250953_56d8078f9660471799cb1741a3a45ade.jpg" designation="" enumeration="" data-uuid="c848cd9de0b646e1b3590904031e41f8" sandbox="true">
<title>Front Matter</title>
<exhibit path="frontmatter/fm_cover.html"/>
<exhibit path="frontmatter/fm_titlepage.html"/>
<exhibit path="frontmatter/copyright.html"/>
</chapter>
</unit>
<unit designation="Section" enumeration="1" data-uuid="d1ff46bfa6fe47dda6f27a9d871eb727">
<title>Getting Started</title>
<chapter thumbnailpath="../img/toc_thumbs/ch01_thumb.png" designation="Chapter" enumeration="1" data-uuid="6f33bec0993d4133b75e4bd9b3902ef8" sandbox="false">
<title>SHSAT Basics</title>
<exhibit path="chapter01/ch01_part.html"/>
<exhibit path="chapter01/ch01_reader_0.html"/>
</chapter>
<chapter thumbnailpath="../img/toc_thumbs/ch02_thumb.png" designation="Chapter" enumeration="2" data-uuid="2bf06864e6264270843990fe377ecb41" sandbox="false">
<title>Inside the SHSAT</title>
<exhibit path="chapter02/ch02_reader_0.html"/>
<exhibit path="chapter02/ch02_reader_1.html"/>
</chapter>
</unit>
</spine>
</toc>
This my XSLT script:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:math="http://www.w3.org/2005/xpath-functions/math"
xmlns:xd="http://www.oxygenxml.com/ns/doc/xsl"
xmlns:xhtml="http://www.w3.org/1999/xhtml"
xmlns:s9ml="http://www.standardnine.com/s9ml" exclude-result-prefixes="xs math xd xhtml s9ml"
xmlns:epub="http://www.idpf.org/2007/ops"
version="3.0">
<xsl:output method="xhtml"/>
<xsl:param name="topicPrefix"/>
<xsl:template match="/">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>EPUB 3 Specifications - Table of Contents</title>
<link rel="stylesheet" type="text/css" href="../css/epub-spec.css" />
</head>
<body>
<nav epub:type="toc" id="toc">
<h1 class="title">Table of Contents</h1>
<ol>
<xsl:apply-templates select="//s9ml:exhibit" />
</ol>
</nav>
</body>
</html>
</xsl:template>
<!-- process exhibits referenced from toc.s9ml -->
<xsl:template match="s9ml:exhibit">
<xsl:element name="li" namespace="http://www.w3.org/1999/xhtml">
<xsl:variable name="count" select="position()"/>
<xsl:attribute name="id">
<xsl:value-of select="$topicPrefix"/>
<xsl:number format="0000" level="any"/>
</xsl:attribute>
<xsl:element name="a" namespace="http://www.w3.org/1999/xhtml">
<xsl:attribute name="href">
<xsl:value-of select="#path" />
</xsl:attribute>
<xsl:apply-templates select="document(#path)//xhtml:title">
</xsl:apply-templates>
</xsl:element>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
This is the output I'm getting:
<?xml version="1.0" encoding="UTF-8"?><html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>EPUB 3 Specifications - Table of Contents</title>
<link rel="stylesheet" type="text/css" href="../css/epub-spec.css" />
</head>
<body>
<nav epub:type="toc" id="toc">
<h1 class="title">Table of Contents</h1>
<ol>
<li id="0001">Cover</li>
<li id="0002">Title Page</li>
<li id="0003">Copyright</li>
<li id="0004">Section 1: Getting Started</li>
<li id="0005">SHSAT Basics</li>
<li id="0006">Inside the SHSAT</li>
<li id="0007">Structure of the Test</li>
</ol>
</nav>
</body>
</html>
This is the output I need is:
<?xml version="1.0" encoding="UTF-8"?>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>EPUB 3 Specifications - Table of Contents</title>
<link rel="stylesheet" type="text/css" href="../css/epub-spec.css" />
</head>
<body>
<nav epub:type="toc" id="toc">
<h1 class="title">Table of Contents</h1>
<ol>
<li>Front Matter <ol>
<li id="0001">Cover</li>
<li id="0002">Title Page</li>
<li id="0003">Copyright</li>
</ol>
</li>
<li>Section 1 Getting Started <ol>
<li>Chapter 1 SHSAT Basics <ol>
<li id="0004"><a href="chapter01/ch01_part.html">Section 1: Getting
Started</a></li>
<li id="0005"><a href="chapter01/ch01_reader_0.html">SHSAT
Basics</a></li>
</ol>
</li>
<li>Chapter 2 Inside the SHSAT <ol>
<li id="0006"><a href="chapter02/ch02_reader_0.html">Inside the
SHSAT</a></li>
<li id="0007"><a href="chapter02/ch02_reader_1.html">Structure of
the Test</a></li>
</ol>
</li>
</ol>
</li>
</ol>
</nav>
</body>
</html>
It sounds as if you want to start processing <xsl:apply-templates select="//s9ml:unit"/> instead of <xsl:apply-templates select="//s9ml:exhibit" />, then write a template
<xsl:template mmatch="s9ml:unit | s9ml:chapter">
<li>
<xsl:value-of select="s9ml:title"/>
<ol>
<xsl:apply-templates select="node() except s9ml:title"/>
</ol>
</li>
</xsl:template>
to make sure you get a hierarchy of nested, ordered lists.
The whole snippets assumes you want to output XHTML result elements and have therefore declared xmlns="http://www.w3.org/1999/xhtml" on the xsl:stylesheet root element.
I want to:
Create a file in the same folder where I am running my XSLT stylesheet against.
This new file has a list of href to files with a certain value in the copyrholder element.
Have a relative path in the href.
This is what I currently have:
I create a new topic in the same folder
List of href with absolute uri
Problem: make the absolute path relative to file I just created.
Example
This is the folder I am referencing to and all files have that particular element I want in the list:
C:/dita/file1.dita
C:/dita/file2.dita
C:/dita/file3.dita
C:/dita/file4.dita
C:/dita/en/file5.dita
This is the XSLT I use
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="2.0">
<xsl:template match="/">
<xsl:result-document href="newtopic.dita" doctype-public="-//OASIS//DTD DITA Topic//EN" doctype-system="topic.dtd" indent="yes">
<topic id="to_new_topics">
<xsl:element name="title">New topics</xsl:element>
<xsl:element name="body">
<xsl:variable name="folderURI" select="resolve-uri('.',base-uri())"/>
<ul>
<xsl:for-each select="collection(concat($folderURI, '?select=*.dita;recurse=yes'))//copyrholder[contains(., 'value')]">
<li>
<xsl:element name="xref">
<xsl:attribute name="href">
<xsl:value-of select="base-uri()" />
</xsl:attribute>
</xsl:element>
</li>
</xsl:for-each>
</ul>
</xsl:element>
</topic>
</xsl:result-document>
</xsl:template>
</xsl:stylesheet>
This is the current result:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE topic
PUBLIC "-//OASIS//DTD DITA Topic//EN" "topic.dtd">
<topic id="to_new_topics">
<title>New topics</title>
<body>
<ul>
<li><xref href="file:/C:/´dita/file1.dita"/></li>
<li><xref href="file:/C:/´dita/file2.dita"/></li>
<li><xref href="file:/C:/´dita/file3.dita"/></li>
<li><xref href="file:/C:/´dita/file4.dita"/></li>
<li><xref href="file:/C:/dita/en/file5.dita"/></li>
</ul>
</body>
</topic>
This what I would like to have:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE topic
PUBLIC "-//OASIS//DTD DITA Topic//EN" "topic.dtd">
<topic id="to_new_topics">
<title>New topics</title>
<body>
<ul>
<li><xref href="file1.dita"/></li>
<li><xref href="file2.dita"/></li>
<li><xref href="file3.dita"/></li>
<li><xref href="file4.dita"/></li>
<li><xref href="en/file5.dita"/></li>
</ul>
</body>
</topic>
Anyone whou can help me to make the path relative?
Could this work:
<xsl:value-of select="replace(base-uri(), $folderURI, '') "/>
(did not see this at the comments), since if the problem is the absolute path at the xref, replacing the path with empty value should solve this problem. Or I just understand something terrible wrong. :) This is my tests end result:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE topic
PUBLIC "-//OASIS//DTD DITA Topic//EN" "topic.dtd">
<topic id="to_new_topics">
<title>New topics</title>
<body>
<ul>
<li>
<xref href="en/file3.dita"/>
</li>
<li>
<xref href="file1.dita"/>
</li>
<li>
<xref href="file2.dita"/>
</li>
</ul>
</body>
</topic>
Tested with: XSL, newtopic.xml (to avoid problems and renamed this .xml, not .dita) and all file*.dita files are in the same folder or subfolder.
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 (/)
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.
I have a series of nodes that are direct child nodes to a parent I want to loop over those nodes but have them wrapped in 'groups' of 4... I'm probably not wording this very clearly so this might help;
<span class="child01">#nodename</span>
<span class="child02">#nodename</span>
<span class="child03">#nodename</span>
<span class="child04">#nodename</span>
<span class="child05">#nodename</span>
<span class="child06">#nodename</span>
<span class="child07">#nodename</span>
<span class="child08">#nodename</span>
..
<span class="child32">#nodename</span>
<span class="child33">#nodename</span>
..and so on
Goal
<div class="group">
<span class="child01">#nodename</span>
<span class="child02">#nodename</span>
<span class="child03">#nodename</span>
<span class="child04">#nodename</span>
</div>
<div class="group">
<span class="child05">#nodename</span>
<span class="child06">#nodename</span>
<span class="child07">#nodename</span>
<span class="child08">#nodename</span>
</div>
<div class="group">
..
<span class="child32">#nodename</span>
</div>
<div class="group">
<span class="child33">#nodename</span>
..and so on
I have tried variations on this idea - wrapping the lot in the open and closing group tags and every fourth loop drop in a new close / open pair
<div class="group">
<xsl:for-each select="$currentPage/*">
<span>
<xsl:value-of select="#nodeName" />
</span>
<!--
=============================================================
After very 4th item
=============================================================
-->
<xsl:if test="position() mod 4 = 0">
<xsl:text></div><div class="page"></xsl:text>
</xsl:if>
</xsl:for-each>
</div>
But essentially it seems XSLT won't let me start with a closing unmatched tag
The clkoset solution I ahve found so far is a 'fix' in jquery Wrapping a div around every three divs but I would rather not rely on javascript to format the page.
This transformation:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:param name="pNumCols" select="3"/>
<xsl:template match="/*">
<xsl:apply-templates select="span[position() mod $pNumCols = 1]"/>
</xsl:template>
<xsl:template match="span">
<div>
<xsl:copy-of select=
".|following-sibling::span[not(position() > $pNumCols -1)]"/>
</div>
</xsl:template>
</xsl:stylesheet>
when applied on the provided XML document:
<t>
<span class="child01">#nodename</span>
<span class="child02">#nodename</span>
<span class="child03">#nodename</span>
<span class="child04">#nodename</span>
<span class="child05">#nodename</span>
<span class="child06">#nodename</span>
<span class="child07">#nodename</span>
<span class="child08">#nodename</span> ..
<span class="child32">#nodename</span>
<span class="child33">#nodename</span>
</t>
produces the wanted result:
<div>
<span class="child01">#nodename</span>
<span class="child02">#nodename</span>
<span class="child03">#nodename</span>
</div>
<div>
<span class="child04">#nodename</span>
<span class="child05">#nodename</span>
<span class="child06">#nodename</span>
</div>
<div>
<span class="child07">#nodename</span>
<span class="child08">#nodename</span>
<span class="child32">#nodename</span>
</div>
<div>
<span class="child33">#nodename</span>
</div>
If like me you need to transform the source elements that are being divided by position, use xsl:for-each instead of xsl:copy:
<xsl:template match="span">
<ol>
<xsl:for-each select=".|following-sibling::span[not(position() > $pNumCols -1)]"/>
<li><xsl:value-of select="./text()"/></li>
</xsl:for-each>
</ol>
</xsl:template>
Faced by the same problem, that is wanting to output
<div class="container">
<div class="row">
<div class="col">...</div>
<div class="col"/>...</div>
</div>
<div class="row">
...
</div>
</div>
from a CXML (Collection XML) file (http://gallery.clipflair.net/collection/activities.cxml - the data behind the PivotViewer display at http://gallery.clipflair.net/activity)
I coined up the following, based on other suggestions here, but using "mode" attribute of "template" and "apply-templates" XSL tags instead which make it cleaner I believe:
<?xml version="1.0" encoding="UTF-8"?>
<?altova_samplexml http://gallery.clipflair.net/collection/activities.cxml?>
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:cxml="http://schemas.microsoft.com/collection/metadata/2009"
exclude-result-prefixes="cxml"
>
<xsl:output method="html" version="4.0" encoding="UTF-8" indent="yes"/>
<xsl:param name="COLUMNS" select="2"/>
<!-- ########################### -->
<xsl:template match="/">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>ClipFlair Activities</title>
<link rel="stylesheet" type="text/css" href="style.css"/>
</head>
<body>
<xsl:apply-templates/>
</body>
</html>
</xsl:template>
<!-- ########################### -->
<xsl:template match="cxml:Collection">
<div class="container">
<xsl:apply-templates/>
</div>
</xsl:template>
<!-- ########################### -->
<xsl:template match="cxml:Items">
<xsl:apply-templates select="cxml:Item[position() mod $COLUMNS = 1]" mode="row"/>
</xsl:template>
<!-- ########################### -->
<xsl:template match="cxml:Item" mode="row">
<div class="row">
<div>----------</div>
<xsl:apply-templates select=".|following-sibling::cxml:Item[position() < $COLUMNS]" mode="col"/>
</div>
</xsl:template>
<xsl:template match="cxml:Item" mode="col">
<xsl:variable name="URL" select="#Href"/>
<xsl:variable name="FILENAME" select="cxml:Facets/cxml:Facet[#Name='Filename']/cxml:String/#Value"/>
<div class="col">
<xsl:value-of select="$FILENAME"/> --- <xsl:value-of select="$URL"/>
</div>
</xsl:template>
<!-- ########################### -->
<xsl:template match="*">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="text()|#*">
</xsl:template>
</xsl:stylesheet>
the output from the above when run in Altova XMLSpy tool (note that it uses altova_samplexml processor instruction to find the XML data) is:
2DaysInParis-OpenActivity-CapRev-FR-EN.clipflair --- http://studio.clipflair.net/?activity=2DaysInParis-OpenActivity-CapRev-FR-EN.clipflair
Abu_Dukhan-CapRev-A1-AR.clipflair --- http://studio.clipflair.net/?activity=Abu_Dukhan-CapRev-A1-AR.clipflair
----------
AFarewellToArms-RevCap-C2-EN.clipflair --- http://studio.clipflair.net/?activity=AFarewellToArms-RevCap-C2-EN.clipflair
agComhaireamhCountingRND.clipflair --- http://studio.clipflair.net/?activity=agComhaireamhCountingRND.clipflair
----------
Al-imtihan-CapRev-B1-AR.clipflair --- http://studio.clipflair.net/?activity=Al-imtihan-CapRev-B1-AR.clipflair
AlBar-Cap-B1-B2-IT.clipflair --- http://studio.clipflair.net/?activity=AlBar-Cap-B1-B2-IT.clipflair
...