Format date compare date XSLT - date

I have an XML file with description and date about events like this:
<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="timedate.xsl"?>
<catalog>
<event>
<name>AAA Festival</name>
<place>New York</place>
<country>USA</country>
<date>19/11/2013</date>
</event>
<event>
<name>BBB Festival</name>
<place>Paris</place>
<country>France</country>
<date>11/10/2013</date>
</event>
<event>
<name>CCC Festival</name>
<place>London</place>
<country>UK</country>
<date>29/09/2013</date>
</event>
</catalog>
and an XSL file:
<?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="/">
<html>
<body>
<h2>Upcoming events</h2>
<table border="1">
<tr bgcolor="#9acd32">
<th>Name</th>
<th>Place</th>
<th>Country</th>
<th>Date</th>
</tr>
<xsl:for-each select="catalog/event">
<xsl:sort select="date" order="descending"/>
<tr>
<td><xsl:value-of select="name"/></td>
<td><xsl:value-of select="place"/></td>
<td><xsl:value-of select="country"/></td>
<td><xsl:value-of select="date"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
I would like to make a page that sort and list only upcoming events (including today date). I'm not able to do this, because dates are not well formatted and I can get current date to compare them and print future events. Please let me know the solution with an example that works. Thanks in advance for your replies and help. Regards!

Idea to compare/sort dates concerned with converting your raw date to number format. For example by formula year*372+12*month*31+day (372 and 31 is ok since you really don't need precise numbers)
If your xml have fixed date format (e.g you sure that 1 is always 01) you can use XPath function substring
EDITED-with respect to your claim I'm placing full sample of xsl.
<?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="/">
<html>
<body>
<h2>Upcoming events</h2>
<table border="1">
<tr bgcolor="#9acd32">
<th>Name</th>
<th>Place</th>
<th>Country</th>
<th>Date</th>
</tr>
<xsl:for-each select="catalog/event">
<xsl:sort
select="number(substring(date, 7, 4))*372+12*31*number(substring(date, 4, 2))+number(substring(date, 1, 2))"
order="descending" data-type="number"/>
<tr>
<td><xsl:value-of select="name"/></td>
<td><xsl:value-of select="place"/></td>
<td><xsl:value-of select="country"/></td>
<td><xsl:value-of select="date"/></td>
<!-- column just for debug-->
<td><xsl:value-of select="number(substring(date, 7, 4))*372+12*31*number(substring(date, 4, 2))+number(substring(date, 1, 2))"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

Related

Why Does My FAMILY Query Fail?

Please have a look at the following code wherein I have a method that searches by family name and another that searches by system. Following the code I have provided the results that were produced by invoking each of these two methods. You can see that the system search returned three patients, the third one having the family name Vaessen. But, when I search for the family name Vaessen a timeout results. Would someone please help me to understand why this is happening?
Note: As you can see from the timeout exception, I am querying the public fhir server http://fhirtest.uhn.ca/baseDstu3
public void findPatientsInFamily(String family) {
System.out.printf("\n\nFinding patients in family %s\n", family);
findPatients(Patient.FAMILY.matches().value(family));
}
public void findPatientsInSystem(String system) {
System.out.printf("\n\nFinding patients in system %s\n", system);
findPatients(Patient.IDENTIFIER.hasSystemWithAnyCode(system));
}
#SuppressWarnings("rawtypes")
public void findPatients(ICriterion criterion) {
try {
Bundle bundle = client.search().forResource(Patient.class).where(criterion).returnBundle(Bundle.class).execute();
for (BundleEntryComponent entry : bundle.getEntry()) {
if (entry.getResource().getResourceType() == ResourceType.Patient) {
Patient patient = (Patient) entry.getResource();
System.out.printf("%s\n", parser.encodeResourceToString(patient));
}
}
}
catch(Exception e) {
System.out.printf("Cannot find patients\n%s\n", e.getMessage());
}
}
Results for the findPatientsInSystem(String system) method:
Finding patients in system http://dmw.levy.com/mrn
<Patient xmlns="http://hl7.org/fhir">
<id value="4172808"></id>
<meta>
<versionId value="1"></versionId>
<lastUpdated value="2018-06-07T14:10:52.336+00:00"></lastUpdated>
</meta>
<text>
<status value="generated"></status>
<div xmlns="http://www.w3.org/1999/xhtml">
<div class="hapiHeaderText">Rachael
<b>LANEHART </b>
</div>
<table class="hapiPropertyTable">
<tbody>
<tr>
<td>Identifier</td>
<td>12345</td>
</tr>
<tr>
<td>Date of birth</td>
<td>
<span>30 December 1985</span>
</td>
</tr>
</tbody>
</table>
</div>
</text>
<identifier>
<system value="http://dmw.levy.com/mrn"></system>
<value value="12345"></value>
</identifier>
<name>
<family value="Lanehart"></family>
<given value="Rachael"></given>
</name>
<gender value="female"></gender>
<birthDate value="1985-12-30"></birthDate>
</Patient>
<Patient xmlns="http://hl7.org/fhir">
<id value="4149602"></id>
<meta>
<versionId value="1"></versionId>
<lastUpdated value="2018-06-06T20:52:11.831+00:00"></lastUpdated>
</meta>
<text>
<status value="generated"></status>
<div xmlns="http://www.w3.org/1999/xhtml">
<div class="hapiHeaderText">Ravi
<b>THAKKAR </b>
</div>
<table class="hapiPropertyTable">
<tbody>
<tr>
<td>Identifier</td>
<td>12345</td>
</tr>
<tr>
<td>Date of birth</td>
<td>
<span>14 April 1962</span>
</td>
</tr>
</tbody>
</table>
</div>
</text>
<identifier>
<system value="http://dmw.levy.com/mrn"></system>
<value value="12345"></value>
</identifier>
<name>
<family value="Thakkar"></family>
<given value="Ravi"></given>
</name>
<gender value="male"></gender>
<birthDate value="1962-04-14"></birthDate>
</Patient>
<Patient xmlns="http://hl7.org/fhir">
<id value="4013201"></id>
<meta>
<versionId value="1"></versionId>
<lastUpdated value="2018-06-01T18:30:23.902+00:00"></lastUpdated>
</meta>
<text>
<status value="generated"></status>
<div xmlns="http://www.w3.org/1999/xhtml">
<div class="hapiHeaderText">Robert Jozef
<b>VAESSEN </b>
</div>
<table class="hapiPropertyTable">
<tbody>
<tr>
<td>Identifier</td>
<td>12345</td>
</tr>
<tr>
<td>Date of birth</td>
<td>
<span>30 January 1954</span>
</td>
</tr>
</tbody>
</table>
</div>
</text>
<identifier>
<system value="http://dmw.levy.com/mrn"></system>
<value value="12345"></value>
</identifier>
<name>
<family value="Vaessen"></family>
<given value="Robert"></given>
<given value="Jozef"></given>
</name>
<gender value="male"></gender>
<birthDate value="1954-01-30"></birthDate>
</Patient>
Results for the findPatientsInFamily(String family) method:
Finding patients in family Vaessen
Cannot find patients
Failed to parse response from server when performing GET to URL http://fhirtest.uhn.ca/baseDstu3/Patient?family=Vaessen - java.net.SocketTimeoutException: Read timed out
The way in which your code queries the FHIR Server should be fine for a Patient search by system or family name.
I tried the public test server through the UI at http://fhirtest.uhn.ca/ and everything appears to be down currently. Every request returns an error. There is already an issue posted here on GIT https://github.com/jamesagnew/hapi-fhir/issues/998.
It is also possible that when the server is back up, there may be so much patient data that your request will still error unless a large connection timeout is set, or more filter criteria is provided.

Orbreon - 2 input fields

I've just started with Orbeon forms and cannot figure out the simplest possible thing (I guess).
I want to have two input fields : one for name, the other for surname. Here is my code :
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:xh="http://www.w3.org/1999/xhtml"
xmlns:xf="http://www.w3.org/2002/xforms"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:ev="http://www.w3.org/2001/xml-events"
xmlns:xxf="http://orbeon.org/oxf/xml/xforms"
xmlns:xforms="http://www.w3.org/2002/xforms">
<head>
<xforms:model>
<xforms:instance>
<first-name xmlns=""/>
</xforms:instance>
<xforms:instance>
<second-name xmlns=""/>
</xforms:instance>
</xforms:model>
</head>
<body>
<xforms:input ref="/first-name">
<xforms:label>Sth</xforms:label>
</xforms:input>
<br/>
<xforms:input ref="/second-name">
<xforms:label>Sth2</xforms:label>
</xforms:input>
</body> </html>
For some reason on the page I can see only the first one (first-name input field). What am I doing wrong ?
Here is a working example:
<xh:html
xmlns:xh="http://www.w3.org/1999/xhtml"
xmlns:xf="http://www.w3.org/2002/xforms"
xmlns:xxf="http://orbeon.org/oxf/xml/xforms"
xmlns:ev="http://www.w3.org/2001/xml-events"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xh:head>
<xf:model>
<xf:instance>
<form>
<first-name/>
<last-name/>
</form>
</xf:instance>
</xf:model>
</xh:head>
<xh:body>
<xf:input ref="first-name">
<xf:label>First name:</xf:label>
</xf:input>
<xf:input ref="last-name">
<xf:label>Last name:</xf:label>
</xf:input>
</xh:body>
</xh:html>

xPages date field in IBM Notes 9, the Default value not showing and Picker Icon not aligned properly

I have tested Xpage Application in Notes Client (xpinc) 9 and find the following bugs with Date/Time Picker.
Given default value for the Date field.
When viewing in the xpinc,not able to see the default value in the date field. On click of the Date picker icon, default value is showing up. This may be because dafault value is over laid behind the date picker icon.
Date picker icon is displaying right side instead of left side.
Once we pick the date, we are not able to view the date picker icon any more.
My code follows like,
<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core"
xmlns:xe="http://www.ibm.com/xsp/coreex">
<xp:inputText id="inputText1">
<xp:this.defaultValue><![CDATA[#{javascript:#Date("16/12/2013")}]]></xp:this.defaultValue><xp:dateTimeHelper id="dateTimeHelper1"></xp:dateTimeHelper>
<xp:this.converter>
<xp:convertDateTime type="date"></xp:convertDateTime>
</xp:this.converter>
</xp:inputText>
</xp:view>
When preview in web, the default values coming fine and picker Icon aligned properly. But when preview in IBM Notes 9 (xpinc), The default value not showing in the field. The UI of date field looks bad! Refer the following link
http://www-10.lotus.com/ldd/ndseforum.nsf/xpTopicThread.xsp?documentId=CA3D7B61284FEE3185257B6300352563
seems problem with Notes 9 client.
I have tried again same thing in Notes 9 client. My source code like below
<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core"
xmlns:xe="http://www.ibm.com/xsp/coreex">
<xp:this.beforeRenderResponse><![CDATA[#{javascript:viewScope.DateEntered = viewScope.DateEntered || #Yesterday()}]]></xp:this.beforeRenderResponse>
<xp:table>
<xp:tr>
<xp:td>
<xp:label value="Sample date input" id="label1"></xp:label></xp:td>
<xp:td></xp:td>
</xp:tr>
<xp:tr>
<xp:td></xp:td>
<xp:td></xp:td>
</xp:tr>
<xp:tr>
<xp:td>
<xp:label value="Please enter a date:" id="label2"></xp:label></xp:td>
<xp:td>
<xp:inputText id="inputText1"
value="#{viewScope.DateEntered}">
<xp:this.converter>
<xp:convertDateTime type="date"></xp:convertDateTime>
</xp:this.converter>
<xp:dateTimeHelper></xp:dateTimeHelper>
</xp:inputText>
</xp:td>
</xp:tr>
<xp:tr>
<xp:td>
<xp:label value="Please enter some Text:" id="label3"></xp:label></xp:td>
<xp:td>
<xp:inputText id="inputText2"
value="#{viewScope.textEntered}">
</xp:inputText></xp:td>
</xp:tr>
</xp:table>
</xp:view>
Html code in notes client like below
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
<title></title>
<link rel="stylesheet" type="text/css" href="/xsp/.ibmxspres/.mini/css/#Da&#Ib&2Tcxsp.css&2TcxspLTR.css&2TcxspRCP.css.css">
<script type="text/javascript" src="/xsp/.ibmxspres/dojoroot-1.8.0/dojo/dojo.js" djConfig="locale: 'en-us', parseOnLoad: true"></script>
<script type="text/javascript" src="/xsp/.ibmxspres/.mini/dojo/.en-us/#Ie&#Iu.js"></script>
<script type="text/javascript">dojo.require('ibm.xsp.widget.layout.xspClientDojo')</script>
<script type="text/javascript">dojo.require('ibm.xsp.widget.layout.xspClientRCP')</script>
<script type="text/javascript">dojo.require('dojo.parser')</script>
<script type="text/javascript">dojo.require('ibm.xsp.widget.layout.DateTextBox')</script>
</head>
<body class="xspView tundra">
<form id="view:_id1" method="post" action="/xsp/Dev9!!ESI/Sprint55/AcctMgr.nsf/xpCombo.xsp?1367948337%3FOpenXPage&xspRunningContext=Notes" class="xspForm" enctype="multipart/form-data">
<table><tr><td><span id="view:_id1:label1" class="xspTextLabel">Sample date input</span></td>
<td></td>
</tr>
<tr><td></td>
<td></td>
</tr>
<tr><td><span id="view:_id1:label2" class="xspTextLabel">Please enter a date:</span></td>
<td><input type="text" value="2013-05-06" id="view:_id1:inputText1" name="view:_id1:inputText1" class="xspInputFieldDateTimePicker" dojoType="ibm.xsp.widget.layout.DateTextBox" iconStyleClass="xspInputFieldDatePickerIcon" constraints="{datePattern:"MMM d, yyyy",timePattern:"h:mm:ss a",selector:"date"}"></td>
</tr>
<tr><td><span id="view:_id1:label3" class="xspTextLabel">Please enter some Text:</span></td>
<td><input type="text" id="view:_id1:inputText2" name="view:_id1:inputText2" class="xspInputFieldEditBox"></td>
</tr>
</table>
<input type="hidden" name="$$viewid" id="view:_id1__VUID" value="!dgw1o52zpc!">
<input type="hidden" name="$$xspsubmitid">
<input type="hidden" name="$$xspexecid">
<input type="hidden" name="$$xspsubmitvalue">
<input type="hidden" name="$$xspsubmitscroll">
<input type="hidden" name="view:_id1" value="view:_id1"></form>
<script type="text/javascript">
XSP.addOnLoad(function() {
XSP.attachValidator("view:_id1:inputText1",null,new XSP.DateConverter("MMM d, yyyy","This field is not a valid date."));
});
</script>
<input type="hidden" id="XspBridgeIn">
<input type="hidden" id="XspBridgeOut">
</body>
But still I am facing same issue. Date field not aligned properly
https://www.dropbox.com/s/9bmj3nmcbwy1cxd/DatePicker.jpg
I am using notes 9 client and Xp machine.
Is any problem with my notes client?
Adding the following Css in to xpage, can resolve alignment issue of Date picker in Notes 9 xpinc.
<style type="text/css">
.xspInputFieldEditBox > div {
width:auto;
}
</style>
Your source code will be following
<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core"
xmlns:xe="http://www.ibm.com/xsp/coreex">
<style type="text/css">
.xspInputFieldEditBox > div {
width:auto;
}
</style>
<xp:inputText id="inputText1" value="#{viewScope.inputText1}"
defaultValue="#{javascript:#Now()}">
<xp:this.converter>
<xp:convertDateTime type="date" />
</xp:this.converter>
<xp:dateTimeHelper />
</xp:inputText>
</xp:view>
Even with change of theme such as One UI V2, 2.1, web standard you can resolve this issue
I tried this:
<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core" xmlns:xe="http://www.ibm.com/xsp/coreex">
<xp:this.beforeRenderResponse><![CDATA[#{javascript:viewScope.DateEntered = viewScope.DateEntered || #Yesterday();}]]>
</xp:this.beforeRenderResponse>
<xe:formTable id="formTable1" formTitle="Sample date input"
formDescription="Test for date functionality">
<xe:formRow id="formRow1" for="inputText1" label="Please enter a date:"
labelPosition="left">
<xp:inputText id="inputText1"
value="#{viewScope.DateEntered}">
<xp:this.converter>
<xp:convertDateTime type="date"></xp:convertDateTime>
</xp:this.converter>
<xp:dateTimeHelper></xp:dateTimeHelper>
</xp:inputText>
</xe:formRow>
<xe:formRow id="formRow2" for="inputText2" label="Please enter some Text:"
labelPosition="left">
<xp:inputText id="inputText2"
value="#{viewScope.textEntered}">
</xp:inputText>
</xe:formRow>
</xe:formTable>
</xp:view>
Works flawless. How does your code look like? If you use data binding, then NO default value is pulled from the control's properties, but the value provided by the variable the control is bound to. Binding always trumps defaults.
When I look at the page source (that what gets generated in the client in this case - which you can see on the machine where your Domino designer is installed, then I get:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
<title></title>
<link rel="stylesheet" type="text/css" href="/xsp/.ibmxspres/.mini/css/2Ojcore.css&2Ojdojo.css&2OldefaultTheme.css&2OldojoTheme.css&#Da&#Ib&#Th&#Ti.css">
<script type="text/javascript" src="/xsp/.ibmxspres/dojoroot-1.8.0/dojo/dojo.js" djConfig="locale: 'en-us', parseOnLoad: true"></script>
<script type="text/javascript">dojo.registerModulePath('extlib', '/xsp/.ibmxspres/.extlib');</script>
<script type="text/javascript" src="/xsp/.ibmxspres/.mini/dojo/.en-us/#Eya&#Ie&#Iu.js"></script>
<script type="text/javascript">dojo.require('ibm.xsp.widget.layout.xspClientDojo')</script>
<script type="text/javascript">dojo.require('ibm.xsp.widget.layout.xspClientRCP')</script>
<script type="text/javascript">dojo.require('dojo.parser')</script>
<script type="text/javascript">dojo.require('extlib.theme.OneUIA11Y')</script>
<script type="text/javascript">dojo.require('ibm.xsp.widget.layout.DateTextBox')</script>
</head>
<body class="xsp lotusui tundra">
<form id="view:_id1" method="post" action="/xsp/My2003Xpages.nsf/Test6.xsp?1367936627%3FOpenXPage&xspRunningContext=Notes" class="lotusForm" enctype="multipart/form-data">
<fieldset id="view:_id1:formTable1">
<table class="lotusFormTable" role="presentation" cellpadding="0" cellspacing="0" border="0"><tbody>
<tr><td class="lotusFormTitle" colspan="3"><h2>Sample date input<div class="lotusMeta">Test for date functionality</div></h2></td></tr>
<tr class="lotusFormFieldRow"><td style="width:15%" class="lotusFormLabel"><label for="view:_id1:inputText1">Please enter a date:</label></td><td><input type="text" value="2013-05-06" id="view:_id1:inputText1" name="view:_id1:inputText1" class="xspInputFieldDateTimePicker" dojoType="ibm.xsp.widget.layout.DateTextBox" iconStyleClass="xspInputFieldDatePickerIcon" constraints="{datePattern:"MMM d, yyyy",timePattern:"h:mm:ss a",selector:"date"}"> <td></td></td></tr>
<tr class="lotusFormFieldRow"><td style="width:15%" class="lotusFormLabel"><label for="view:_id1:inputText2">Please enter some Text:</label></td><td><input type="text" id="view:_id1:inputText2" name="view:_id1:inputText2" class="xspInputFieldEditBox"><td></td></td></tr>
</tbody>
</table>
</fieldset>
<input type="hidden" name="$$viewid" id="view:_id1__VUID" value="!dgw05ue5xc!">
<input type="hidden" name="$$xspsubmitid">
<input type="hidden" name="$$xspexecid">
<input type="hidden" name="$$xspsubmitvalue">
<input type="hidden" name="$$xspsubmitscroll">
<input type="hidden" name="view:_id1" value="view:_id1"></form>
<script type="text/javascript">
XSP.addOnLoad(function() {
XSP.attachValidator("view:_id1:inputText1",null,new XSP.DateConverter("MMM d, yyyy","This field is not a valid date."));
});
</script>
<input type="hidden" id="XspBridgeIn">
<input type="hidden" id="XspBridgeOut">
</body>
</html>
What do you get?

how to select table column by column header name with xpath

I have a table of results and it looks like following:
<table>
<thead>
<tr>
<th>Id</th>
<th>Type</th>
<th>Amount</th>
<th>Price</th>
<th>Name</th>
<th>Expiration</th>
</tr>
</thead>
<tbody>
<tr>
<td>123</td>
<td>Paper</td>
<td>10 pcs.</td>
<td>$10</td>
<td>Premium Copier paper</td>
<td>None</td>
</tr>
<tr>
<td>321</td>
<td>Paper</td>
<td>20 pcs.</td>
<td>$20</td>
<td>Extra Copier paper</td>
<td>None</td>
</tr>
</tbody>
And i want to select the whole column by its name with xpath e.g. i want the returned result to be an array of {<td>$10</td>, <td>$20</td>} if selected by column name "Price".
I'm new to xpath and not really sure how to do this, but i'm pretty sure it's possible.
Ok, i've found the answer that would suffice and look quite elegant. Here goes the required XPath string:
//table/tbody/tr/td[count(//table/thead/tr/th[.="$columnName"]/preceding-sibling::th)+1]
Put a name of the column instead of $columnName. This works well for me. There's no XSL or anything, just pure xpath string. How to apply it - it's another question.
You could use this XPath:
/table/tbody/tr/td[count(preceding-sibling::td)+1 = count(ancestor::table/thead/tr/th[.='Price']/preceding-sibling::th)+1]
I would think testing the position (position()) of the td against the position of the relevant th would work, but it didn't seem to when I was testing.
If you've found a solution, I suggest posting it as an answer here, but just for fun, this is how I would approach this:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes" omit-xml-declaration="yes"/>
<xsl:key name="kCol" match="td" use="count(. | preceding-sibling::td)"/>
<xsl:param name="column" select="'Price'" />
<xsl:template match="#* | node()">
<xsl:copy>
<xsl:apply-templates select="#* | node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="/">
<found>
<xsl:apply-templates select="table/thead/tr/th" />
</found>
</xsl:template>
<xsl:template match="th">
<xsl:if test=". = $column">
<xsl:apply-templates select="key('kCol', position())" />
</xsl:if>
</xsl:template>
</xsl:stylesheet>
When run with "Price" as the parameter value:
<found>
<td>$10</td>
<td>$20</td>
</found>
When run with "Name" as the parameter value:
<found>
<td>Premium Copier paper</td>
<td>Extra Copier paper</td>
</found>

Umbraco XSLT search page navigation using input onchange

I have created a pagination input that on change will go to the value entered into the input.
It will detect the page range and allow navigation between those pages in that range.
e.g /image-gallery-album-1.aspx?page=3
<form type="get" onchange="return false">
<div class="pagerUI">
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<!-- previous page -->
<xsl:if test="$page > 1">
<td class="pager-prev"><a class="previous" href="{concat('?page=', $page - 1, $qs)}" title="Previous page">‹</a></td>
</xsl:if>
<td>Page</td>
<td><input type="number" name="page" id="page" min="1" >
<xsl:choose>
<xsl:when test="$page=1">
<xsl:attribute name="value">1</xsl:attribute>
</xsl:when>
<xsl:otherwise>
<xsl:attribute name="value"> <xsl:value-of select="$currentPageNumber" /> </xsl:attribute>
</xsl:otherwise>
</xsl:choose>
<xsl:attribute name="max"> <xsl:value-of select="$numberOfPages"/> </xsl:attribute>
</input></td>
<td>of <xsl:value-of select="$numberOfPages"/></td>
<!-- next page -->
<xsl:if test="$page * $resultsPerPage < count($matchedNodes)">
<td class="pager-next"><a class="next" href="{concat('?page=', $page + 1, $qs)}" title="Next page">›</a></td>
</xsl:if>
</tr>
</table>
</div>
</form>
However, when I added this to the XSLTSearch code it doesn't work as the URL loses the search string.
So instead of navigating to: /image-search.aspx?search=football&page=3
It navigates to: /image-search.aspx?page=3 Which doesn't display any results on that page as it's missing the search criteria to display the search results.
I tried to change the form and include an "action" that would change the URL to include the search value but I can't include the input value as it's dynamic.
For example with the below form if I enter any value into the input the URL updates to following: /image-search.aspx?search=otbra&page= It's missing the entered number of the input value.
Search form with onchange and action and method post attributes:
<form type="get" onchange="return false">
<xsl:attribute name="method"> <xsl:text>post</xsl:text> </xsl:attribute>
<xsl:attribute name="action"> <xsl:text>?search=</xsl:text> <xsl:value-of select="$search"/><xsl:text>&</xsl:text>page= (input value)</xsl:attribute>
Is there some javascript or some way of detecting the value submitted and parsing it into the search string of the URL?
Any assistance would be appreciated. Cheers, JV
NOTE: As comment on your post says the likely issue is with the $qs variable, however here's an explanation of how you can get Query String values in Umbraco, for reference.
In Umbraco you can retrieve a Query string value in XSLT using umbraco.library
So to retrieve the value of search you would call something like:
<xsl:variable name="searchValue" select="umbraco.library:RequestQueryString('search')"/>
This creates a variable called searchValue which you can then use to re-inject the query string value in your url.
Something like this:
<a class="next" href="{concat('?page=', $page + 1, '&search=', $searchValue)}" title="Next page">›</a>
More information on umbraco.library can be found on the our.umbraco.org site.