473,396 Members | 1,703 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Help - I'm unable to template match on XSL Transform

I have the following input XML:
<?xml version="1.0"?>
<ordersubmit xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.company.com/webservices/ordersubmit">
<order>
<header>
<ordername>TestOrder</ordername>
<start>2006-04-11</start>
</header>
</order>
<request>
<requestaction>SaveAsDraft</requestaction>
</request>
</ordersubmit>
and I need to perform an XSLT such that the result is the following
(changing the namespace structure and reformatting the date:
<ordersubmit xmlns="urn:DGCOrder-schema">
<order>
<header>
<ordername>TestOrder</ordername>
<start>04/11/2006</start>
</header>
</order>
<request>
<requestaction>SaveAsDraft</requestaction>
</request>
</ordersubmit>
The following is my current XLST that provides the namespace structure
I need, but I haven't been able to to write a template match that finds
the element named 'start' such that I can reformat the date:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0" xmlns="urn:DGCOrder-schema">
<xsl:output method="xml" indent="yes"/>

<xsl:template match="*">
<xsl:element name="{local-name()}">
<xsl:apply-templates select="@* | node()" />
</xsl:element>
</xsl:template>

</xsl:stylesheet>
Can anyone provide some assistance as to the correct statement to add
to this XSLT to find the 'start' element so I can reformat the date?
Thanks in advance.

Apr 11 '06 #1
4 1566


jjouett wrote:

<start>2006-04-11</start> <start>04/11/2006</start>


Add a template
<xsl:template xmlns:os="http://www.company.com/webservices/ordersubmit"
match="os:start">
<xsl:element name="{local-name()}">
<xsl:value-of select="concat(substring(., 6, 2), '/',
substring(., 9, 2), '/', substring(., 1, 4))" />
</xsl:element>
</xsl:template>
--

Martin Honnen
http://JavaScript.FAQTs.com/
Apr 11 '06 #2
Works great - thanks!

Apr 11 '06 #3
you can process the start element by filtering on the name of node as shown
below.

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0" xmlns="urn:DGCOrder-schema">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="*">
<xsl:element name="{local-name()}">
<xsl:choose>
<xsl:when test="local-name()='start'">
<!--process your date here-->
<xsl:value-of select="processedDate"/>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="@* | node()" />
</xsl:otherwise>
</xsl:choose>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
hope this helps,
swapna

"jjouett" <jj*****@necam.com> wrote in message
news:11**********************@e56g2000cwe.googlegr oups.com...
I have the following input XML:
<?xml version="1.0"?>
<ordersubmit xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.company.com/webservices/ordersubmit">
<order>
<header>
<ordername>TestOrder</ordername>
<start>2006-04-11</start>
</header>
</order>
<request>
<requestaction>SaveAsDraft</requestaction>
</request>
</ordersubmit>
and I need to perform an XSLT such that the result is the following
(changing the namespace structure and reformatting the date:
<ordersubmit xmlns="urn:DGCOrder-schema">
<order>
<header>
<ordername>TestOrder</ordername>
<start>04/11/2006</start>
</header>
</order>
<request>
<requestaction>SaveAsDraft</requestaction>
</request>
</ordersubmit>
The following is my current XLST that provides the namespace structure
I need, but I haven't been able to to write a template match that finds
the element named 'start' such that I can reformat the date:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0" xmlns="urn:DGCOrder-schema">
<xsl:output method="xml" indent="yes"/>

<xsl:template match="*">
<xsl:element name="{local-name()}">
<xsl:apply-templates select="@* | node()" />
</xsl:element>
</xsl:template>

</xsl:stylesheet>
Can anyone provide some assistance as to the correct statement to add
to this XSLT to find the 'start' element so I can reformat the date?
Thanks in advance.

Apr 11 '06 #4
Just add a template that matches your text node inside a start element
and output the processed date there instead of copying the text node as
it was:

<xsl:template match="text()[parent::o:start]"
xmlns:o="http://www.company.com/webservices/ordersubmit">
<xsl:value-of select="substring-before(substring-after(., '-'),
'-')"/>
<xsl:text>/</xsl:text>
<xsl:value-of select="substring-after(substring-after(., '-'),
'-')"/>
<xsl:text>/</xsl:text>
<xsl:value-of select="substring-before(., '-')"/>
</xsl:template>

Best Regards,
George
---------------------------------------------------------------------
George Cristian Bina
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com

Apr 12 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Bob | last post by:
I am having problems turning my xml into html for display. A sample xml file is given below, followed by my pathetic xslt attempt to transform it into html. A textual representation of what I was...
5
by: dennis | last post by:
Hi, First of all, hi to you all. I'm working on a Delphi project wich is becoming near it's deadline. I have a very simple XSLT question wich i hope one of you folks can help me with? The...
12
by: Amanda | last post by:
I have tried everything with this! I get an error stating "Index was outside the bounds of the array" My code looks like this.... xmlDoc = New XmlDocument() xmlDoc.Load("xml.doc") xslDoc...
8
by: Larry Coon | last post by:
I'm trying to use xsl for the first time, and as with any first-time attempt, I'm running into problems. I'm trying to transform an XML document into another XML document with a slightly...
4
by: J | last post by:
I've spent most of the day on this, and I just can't seem to find a solution, please help me! :) I'm recieving XML that I can't modify that looks like: <?xml version="1.0"?> <Doc> <Page>...
1
by: shapper | last post by:
Hello, I am trying to convert an Asp.Net XML sitemap file in a Google XMl sitemap file using a XSL file using an HttpHandler. Everything seems well in my code but I am getting an error: XML...
2
by: shapper | last post by:
Hello, I am for days trying to apply a XSL transformation to a XML file and display the result in a the browser. I am using Asp.Net 2.0. Please, could someone post just a simple code example,...
1
by: Candle | last post by:
I am having a problem with writing an XSL Transform. Please help. Note: I know this a long post but I wanted to provide as must detail as possible. Any help would be appreciated. (Just started...
3
by: Simon Brooke | last post by:
As various people will have noticed, I've been having a lot of trouble with XSL lately. Brief history: I wrote myself an XML toolkit back in 2000, and it worked well enough for me, so it's been...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.