Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 23rd, 2009, 06:50 AM
Friend of Wrox
 
Join Date: Jan 2006
Posts: 131
Thanks: 10
Thanked 0 Times in 0 Posts
Default Retrieving Current Date/Time with Javascript

XSLT 1.0

Hi,

I need to return the current system Date/Time via javascript from one XSLT file to another.

I have included both of my XSLT programs below:

1. XML conversion script (Calling file)
Code:
 
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:mi="http://schemas.microsoft.com/dynamics/2006/02/documents/MovementDelivery" xmlns:date="//vee1/E:/FTPRoot/trans/xsl/CALjs-functions">
 
<!-- Import the CAL js-functions template -->
<xsl:import href="CALjs-functions.xslt"/>
 
<xsl:variable name="str1" select="Envelope/Body/mi:MovementDelivery/mi:VCTMovements[@class='entity']/mi:RecVersion"/>
<xsl:variable name="strSrceEndPt" select="./Envelope/Header/SourceEndpoint"/>
<xsl:variable name="strDocPurpose" select="Envelope/Body/mi:MovementDelivery/mi:DocPurpose"/>
 
<xsl:template match="/">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="/">
<xsl:call-template name="DelvyNotif"/> 
</xsl:template>
 
<xsl:template name="DelvyNotif">
<xsl:element name="DocumentCreated">
<xsl:attribute name="DateTimeType">Document Created</xsl:attribute>
<xsl:value-of select="js-function:DateTimeNow()"/>
</xsl:element>
</xsl:template>
 
<xsl:template name="copy">
<xsl:copy>
<xsl:for-each select="@*">
<xsl:copy/>
</xsl:for-each>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
 
</xsl:stylesheet>
2. XSLT containing Javascript function (Called file)
Code:
 
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" extension-element-prefixes="js-function" xmlns:js-function="//vee1/E:/FTPRoot/trans/xsl/CALjs-functions">
<msxsl:script language="javascript" implements-prefix="js-function">
 
function DateTimeNow()
{
var now;var year;var month;var monthday;var weekday;var hours;var mins;var secs;var mills;
{
now = new Date();
year = now.getYear(); 
month = now.getMonth();
monthday = now.getDate(); 
// weekday is NOT used in the returning value (0 = Sunday, 1 = Monday)
//weekday = now.getDay();
hours = now.getHours();
mins = now.getMinutes();
secs = now.getSeconds();
// 2 Decimal places....
mills = Math.floor(now.getMilliseconds() / 10);
// Original advise was for 1/10th Sec - (i.e. /100) this converts to 1 Dec Place
// (if used, there would be NO use for the 'CDATA' statement - BUT change to mills=mills+"0";).
// 1 Decimal Place....
// mills = Math.floor(now.getMilliseconds() / 100);
{
<![CDATA[if (mills<10)]]>
{
mills="0"+mills;
}
<![CDATA[if (secs<10)]]>
{
secs="0"+secs;
}
<![CDATA[if (mins<10)]]>
{
mins="0"+mins;
}
<![CDATA[if (hours<10)]]>
{
hours="0"+hours;
}
<![CDATA[if (monthday<10)]]>
{
monthday="0"+monthday;
}
 
// January = 0, December = 11
month=month + 1
 
<![CDATA[if (month<10)]]>
{
month="0"+month; 
}
 
<![CDATA[if (year<10)]]>
{
year="0"+year;
}
return year + month + monthday + " " + hours + ":" + mins + secs + mills;
}
}
}
 
</msxsl:script>
</xsl:stylesheet>
When the 1st file tries to execute the value of 'select="js-function:DateTimeNow()"', the following error occurs:
'Error in XPath expression, Invalid prefix'

I've used similar javascript functions within XSLT before, but I can't see where I'm going wrong. Can anyone help please?

Thanks in advance,
__________________
Neal

A Northern Soul

Last edited by Neal; January 23rd, 2009 at 06:53 AM..
 
Old January 23rd, 2009, 07:35 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

Define the prefix for the extension function in your main stylesheet:
Code:
<xsl:stylesheet
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:js-function="//vee1/E:/FTPRoot/trans/xsl/CALjs-functions"
  version="1.0">
That should fix the problem I think but test that yourself.
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
 
Old January 23rd, 2009, 09:59 AM
Friend of Wrox
 
Join Date: Jan 2006
Posts: 131
Thanks: 10
Thanked 0 Times in 0 Posts
Default

Hi Martin,

Thanks - Unfortunately I realise that this was a typo whilst testing, so a big sorry for that. The file has been updated below, but I'm getting the new error:
'Error in XPath expression, Function not in namespace'

Code:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:mi="http://schemas.microsoft.com/dynamics/2006/02/documents/MovementDelivery" xmlns:js-function="//vee1/E:/FTPRoot/trans/xsl/CALjs-functions">
 
<!-- Import the CAL js-functions template -->
<xsl:import href="CALjs-functions.xslt"/>
 
<xsl:variable name="str1" select="Envelope/Body/mi:MovementDelivery/mi:VCTMovements[@class='entity']/mi:RecVersion"/>
<xsl:variable name="strSrceEndPt" select="./Envelope/Header/SourceEndpoint"/>
<xsl:variable name="strDocPurpose" select="Envelope/Body/mi:MovementDelivery/mi:DocPurpose"/>
 
<xsl:template match="/">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="/">
<xsl:call-template name="DelvyNotif"/> 
</xsl:template>
 
<xsl:template name="DelvyNotif">
<xsl:element name="DocumentCreated">
<xsl:attribute name="DateTimeType">Document Created</xsl:attribute>
<xsl:value-of select="js-function:DateTimeNow()"/>
</xsl:element>
</xsl:template>
 
<xsl:template name="copy">
<xsl:copy>
<xsl:for-each select="@*">
<xsl:copy/>
</xsl:for-each>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
 
</xsl:stylesheet>
Any ideas, please?
__________________
Neal

A Northern Soul

Last edited by Neal; January 23rd, 2009 at 10:03 AM..
 
Old January 23rd, 2009, 10:21 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

Which XSLT processor are you using? Is that MSXML (3 or 4 or 5 or 6)? How do you run the transformation exactly?
Can you post a minimal but complete XML document that causes that error with the stylesheets you posted?
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
 
Old January 23rd, 2009, 11:22 AM
Friend of Wrox
 
Join Date: Jan 2006
Posts: 131
Thanks: 10
Thanked 0 Times in 0 Posts
Default

I'm testing this using XMLSpy (before it goes live)

An altered/compact version of the XML document is:

Code:
 
<?xml version="1.0" encoding="UTF-8"?>
<Envelope>
<Header>
<MessageId>{XXAE79-7XXX-4XXX-B0XX-5XX0BX80XXXA}</MessageId>
<SourceEndpointUser/>
<SourceEndpoint>RM</SourceEndpoint>
<DestinationEndpoint>Out</DestinationEndpoint>
<Action>findListMovementInstruction</Action>
<RequestMessageId/>
</Header>
<Body>
<VCTMovementInstruction xmlns="http://schemas.microsoft.com/dynamics/2006/02/documents/VCTMovementInstruction">
<DocPurpose>Original</DocPurpose>
<SenderId>zm</SenderId>
<VCTMovements class="entity">
<DlvMode>Road</DlvMode>
<HasClaim>No</HasClaim>
<RecId>5637160753</RecId>
<RecVersion>1</RecVersion>
<VCTActualTime>00:00:00</VCTActualTime>
<VCTAdditionalHaulageToVendor>No</VCTAdditionalHaulageToVendor>
<VCTAmended>No</VCTAmended>
<VCTAnalysisEntered>No</VCTAnalysisEntered>
<VCTBulkMovements>No</VCTBulkMovements>
<VCTCalenderOption>No</VCTCalenderOption>
<VCTClaimsEntered>No</VCTClaimsEntered>
<VCTCollectAccepted>No</VCTCollectAccepted>
<VCTCollectAddress>Acme Ltd,
Add1
Add2
Add3
Great Britain
AA123AA</VCTCollectAddress>
<VCTCollectCity>SouthNam</VCTCollectCity>
<VCTCollectFromTime>00:00:00</VCTCollectFromTime>
<VCTCollectStateId>Dors</VCTCollectStateId>
<VCTCollectStreet>Acme Ltd,
Add1 Add2,</VCTCollectStreet>
<VCTCollectToTime>00:00:00</VCTCollectToTime>
<VCTCollectZipCodeId>PA1 8ZZ</VCTCollectZipCodeId>
<VCTCombinedLoad>No</VCTCombinedLoad>
<VCTCreateTime>57406</VCTCreateTime>
<VCTCustAccount>S000476</VCTCustAccount>
<VCTCustInvoiceAccount>S000476</VCTCustInvoiceAccount>
<VCTCustInvoiceName>R.B. Smith</VCTCustInvoiceName>
<VCTCustName>R.C. Smith</VCTCustName>
<VCTDeliverFromTime>00:00:00</VCTDeliverFromTime>
<VCTDeliverToTime>00:00:00</VCTDeliverToTime>
<VCTDeliveryAddress>WernTest
Add1
Add2
Add3
Great Britain
AA123WH</VCTDeliveryAddress>
<VCTDeliveryCity>Newton</VCTDeliveryCity>
<VCTDeliveryName>R.C. Smith</VCTDeliveryName>
<VCTDeliveryStateId>Pous</VCTDeliveryStateId>
<VCTDeliveryStreet>WernTest
Aberhafesp</VCTDeliveryStreet>
<VCTDeliveryZipCodeId>SY163NH</VCTDeliveryZipCodeId>
<VCTFaxSentToHaulier>No</VCTFaxSentToHaulier>
<VCTHaulageAmount>203.00</VCTHaulageAmount>
<VCTHaulageCappedCharge>No</VCTHaulageCappedCharge>
<VCTHaulagePrice>7.00</VCTHaulagePrice>
<VCTHaulageQty>Collected</VCTHaulageQty>
<VCTHaulierAccount>P000912</VCTHaulierAccount>
<VCTHaulierName>M&amp;D Transport</VCTHaulierName>
<VCTIntervalPeriod>Day</VCTIntervalPeriod>
<VCTInventLocationId>TE</VCTInventLocationId>
<VCTInventLocationName>Ternhill</VCTInventLocationName>
<VCTIssued>No</VCTIssued>
<VCTItemGroupDesc>Feed Wheat</VCTItemGroupDesc>
<VCTItemGroupId>FW</VCTItemGroupId>
<VCTItemId>TE2000</VCTItemId>
<VCTItemName>TE2000</VCTItemName>
<VCTMark>No</VCTMark>
<VCTMovementFrmTemp>No</VCTMovementFrmTemp>
<VCTMovementId>00000427_166</VCTMovementId>
<VCTMovementStatus>Created</VCTMovementStatus>
<VCTMovementType>Outbound</VCTMovementType>
<VCTPlannedCollectFromDate>2009-01-08</VCTPlannedCollectFromDate>
<VCTPlannedCollectToDate>2009-01-08</VCTPlannedCollectToDate>
<VCTPlannedDeliverFromDate>2009-01-08</VCTPlannedDeliverFromDate>
<VCTPlannedDeliverToDate>2009-01-08</VCTPlannedDeliverToDate>
<VCTPlannedQty>29.000</VCTPlannedQty>
<VCTPlannedTime>00:00:00</VCTPlannedTime>
<VCTPriceUpdateManually>Yes</VCTPriceUpdateManually>
<VCTProcessed>No</VCTProcessed>
<VCTProfitShareCalculated>No</VCTProfitShareCalculated>
<VCTProfitShareShouldCalc>No</VCTProfitShareShouldCalc>
<VCTPurchAgentDetails>No</VCTPurchAgentDetails>
<VCTReceived>No</VCTReceived>
<VCTRejectionPending>No</VCTRejectionPending>
<VCTRejectionType>None</VCTRejectionType>
<VCTReplacementRequired>No</VCTReplacementRequired>
<VCTSalesAgentDetails>No</VCTSalesAgentDetails>
<VCTSalesId>00000174_044</VCTSalesId>
<VCTSalesInventTransId>00001475_044</VCTSalesInventTransId>
<VCTStorageComplete>No</VCTStorageComplete>
<VCTWeighbridge>No</VCTWeighbridge>
<VCTWeighbridgeExported>No</VCTWeighbridgeExported>
<SalesLine class="entity">
<Blocked>No</Blocked>
<CaseTagging>No</CaseTagging>
<Complete>No</Complete>
<ConfirmedDlv>2009-01-08</ConfirmedDlv>
<CurrencyCode>GBP</CurrencyCode>
<CustAccount>S000016</CustAccount>
<CustGroup>Farm</CustGroup>
<DeliveryAddress>WernTest
Add1
Add2
Add3
Great Britain
AA123WH</DeliveryAddress>
<DeliveryCity>Newtown</DeliveryCity>
<DeliveryCountryRegionId>GB</DeliveryCountryRegionId>
<DeliveryDateControl>No</DeliveryDateControl>
<DeliveryName>R.C. Smith</DeliveryName>
<DeliveryState>Pous</DeliveryState>
<DeliveryStreet>WernTest
Test</DeliveryStreet>
<DeliveryType>None</DeliveryType>
<DeliveryZipCode>SY173NA</DeliveryZipCode>
<DlvMode>Road</DlvMode>
<InventDimId>00000848_076</InventDimId>
<InventRefType>None</InventRefType>
<InventTransId>00001475_074</InventTransId>
<ItemId>TE2000</ItemId>
<ItemTagging>No</ItemTagging>
<LineAmount>1740.00</LineAmount>
<LineNum>2.0000000000</LineNum>
<Name>TE1000</Name>
<PalletTagging>No</PalletTagging>
<PriceUnit>1.000</PriceUnit>
<QtyOrdered>29.000</QtyOrdered>
<ReceiptDateRequested>2009-01-08</ReceiptDateRequested>
<RecId>5637176911</RecId>
<RecVersion>1935928490</RecVersion>
<RemainInventPhysical>29.000</RemainInventPhysical>
<RemainSalesPhysical>29.000</RemainSalesPhysical>
<Reservation>None</Reservation>
<SalesGroup>SG2</SalesGroup>
<SalesId>00000177_046</SalesId>
<SalesPrice>60.00</SalesPrice>
<SalesQty>29.000</SalesQty>
<SalesStatus>Backorder</SalesStatus>
<SalesType>Sales</SalesType>
<SalesUnit>MT</SalesUnit>
<Scrap>No</Scrap>
<ShippingDateRequested>2009-01-08</ShippingDateRequested>
<StatTriangularDeal>No</StatTriangularDeal>
<TaxAutogenerated>Yes</TaxAutogenerated>
<TaxGroup>STD</TaxGroup>
<TaxItemGroup>STD</TaxItemGroup>
<VCTAcknowledged>No</VCTAcknowledged>
<VCTAddress>Test
Add1
Add2
Add3
Great Britain
AA123WH</VCTAddress>
<VCTAddressName>R.C. Smith</VCTAddressName>
<VCTAgentCommissionCalcBy>PlannedQty</VCTAgentCommissionCalcBy>
<VCTAmended>No</VCTAmended>
<VCTAnalysisEntered>No</VCTAnalysisEntered>
<VCTApproved>No</VCTApproved>
<VCTApprover>MG2</VCTApprover>
<VCTBrokerChargeCategory>Fixed</VCTBrokerChargeCategory>
<VCTBrokerCommissionCalcBy>PlannedQty</VCTBrokerCommissionCalcBy>
<VCTBulkMovements>No</VCTBulkMovements>
<VCTChargeCategory>Fixed</VCTChargeCategory>
<VCTCity>Newton</VCTCity>
<VCTClaimsEntered>No</VCTClaimsEntered>
<VCTCollDelPrint>No</VCTCollDelPrint>
<VCTCommissionRate>1.00</VCTCommissionRate>
<VCTCommitmentLevel>Level1</VCTCommitmentLevel>
<VCTContractTypeId>Physical</VCTContractTypeId>
<VCTCountryId>GB</VCTCountryId>
<VCTDelvintolerance>No</VCTDelvintolerance>
<VCTExDelivery>No</VCTExDelivery>
<VCTHaulagePrice>7.00</VCTHaulagePrice>
<VCTHaveMovement>No</VCTHaveMovement>
<VCTIsCommCalculated>No</VCTIsCommCalculated>
<VCTLimitsBreached>No</VCTLimitsBreached>
<VCTLineCode>Physical</VCTLineCode>
<VCTLineEntityType>Movement</VCTLineEntityType>
<VCTMarkedToMarket>No</VCTMarkedToMarket>
<VCTMarketPriceMargin>60.00</VCTMarketPriceMargin>
<VCTMovCommCalc>No</VCTMovCommCalc>
<VCTMoveEndDate>2008-12-21</VCTMoveEndDate>
<VCTMovementId>00000447_144</VCTMovementId>
<VCTMovementMonth>Dec</VCTMovementMonth>
<VCTMovementQty>Delivered</VCTMovementQty>
<VCTMoveStartDate>2008-01-01</VCTMoveStartDate>
<VCtMultiLIne>No</VCtMultiLIne>
<VCTMultilinePeriods>Monthly</VCTMultilinePeriods>
<VCTNetWeight>No</VCTNetWeight>
<VCTOwnHaulage>No</VCTOwnHaulage>
<VCTParentInventTransId>00001574_072</VCTParentInventTransId>
<VCTPostingCheck>No</VCTPostingCheck>
<VCTRefAddressId>000000019_174</VCTRefAddressId>
<VCTRegionId>North</VCTRegionId>
<VCTReviewed>No</VCTReviewed>
<VCTSalesConsolidated>No</VCTSalesConsolidated>
<VCTSelect>No</VCTSelect>
<VCTStateId>Pous</VCTStateId>
<VCTStreet>WeTest
Test</VCTStreet>
<VCTZipCodeId>SY163NH</VCTZipCodeId>
<InventDim class="entity">
<configId>Test</configId>
<InventColorId>TEST</InventColorId>
<inventDimId>00004448_046</inventDimId>
<InventLocationId>TE</InventLocationId>
<InventSizeId>Test</InventSizeId>
<RecId>14444873344440</RecId>
<RecVersion>1</RecVersion>
<InventLocation class="entity">
<InventLocationId>FE</InventLocationId>
<InventLocationType>Standard</InventLocationType>
<Manual>No</Manual>
<MultiSelectRec>No</MultiSelectRec>
<Name>test</Name>
<RecId>39457506060</RecId>
<RecVersion>2444444443</RecVersion>
<ReqRefill>No</ReqRefill>
<VCTDirectDelivery>No</VCTDirectDelivery>
<VCTInventLocationBackFlush>Disabled</VCTInventLocationBackFlush>
<VCTSendDespatchNote>No</VCTSendDespatchNote>
<VCTStorage>No</VCTStorage>
<VCTWarehouseItemValidation>No</VCTWarehouseItemValidation>
<VCTWeighbridge>No</VCTWeighbridge>
<WMSAisleNameActive>No</WMSAisleNameActive>
<WMSLevelNameActive>No</WMSLevelNameActive>
<WMSPositionNameActive>No</WMSPositionNameActive>
<WMSRackNameActive>No</WMSRackNameActive>
</InventLocation>
</InventDim>
</SalesLine>
</VCTMovements>
</VCTMovementInstruction>
</Body>
</Envelope>
__________________
Neal

A Northern Soul
 
Old January 23rd, 2009, 11:28 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

I think msxsl:script is specific to MSXML, Microsoft's COM based XML software solution.
I doubt that XML Spy supports msxsl:script but I am sure Altova has support forums where you could find help on that.
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog





Similar Threads
Thread Thread Starter Forum Replies Last Post
Current Date and Time in XSLT devMc XSLT 6 October 21st, 2007 04:49 AM
getting current date and time in xslt 1.0 ashyabhi_hp XSLT 1 September 24th, 2007 03:17 AM
HELP!!! retrieving time and date from SQL 2005 wearyrecca Visual Basic 2005 Basics 2 September 11th, 2007 10:28 AM
Current date time in XSLT verison 1.0 ksskumar XSLT 1 October 17th, 2006 07:58 AM
how to get current date & time from client machine swati_joshi ASP.NET 1.0 and 1.1 Basics 2 April 28th, 2006 10:18 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.