473,796 Members | 2,599 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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>Test Order</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:DGCO rder-schema">
<order>
<header>
<ordername>Test Order</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:styleshe et xmlns:xsl="http ://www.w3.org/1999/XSL/Transform"
version="1.0" xmlns="urn:DGCO rder-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 1587


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:styleshe et xmlns:xsl="http ://www.w3.org/1999/XSL/Transform"
version="1.0" xmlns="urn:DGCO rder-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="process edDate"/>
</xsl:when>
<xsl:otherwis e>
<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.goo glegroups.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>Test Order</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:DGCO rder-schema">
<order>
<header>
<ordername>Test Order</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:styleshe et xmlns:xsl="http ://www.w3.org/1999/XSL/Transform"
version="1.0" xmlns="urn:DGCO rder-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="substri ng-before(substrin g-after(., '-'),
'-')"/>
<xsl:text>/</xsl:text>
<xsl:value-of select="substri ng-after(substring-after(., '-'),
'-')"/>
<xsl:text>/</xsl:text>
<xsl:value-of select="substri ng-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
1745
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 hoping to see is last. I am using saxon to do the transformation. <?xml version="1.0"?> <Whatever> <Company>Company One <DateRange>21-27Mar2004</DateRange> <SubOrg>Division A
5
1467
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 problem is i need to transform a xml file from this: <root>
12
2144
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 = New XslTransform()
8
1380
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 different format. Here's an example of what the source XML looks like: - - - - begin source.xml - - - - <?xml version="1.0" encoding="UTF-8"?>
4
1471
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> <Item Value="A" Id="1" Count="1"/> <Item Value="B" Id="2" Count="1"/>
1
2210
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 Parsing Error: not well-formed Location: http://localhost:1132/WebSite/Google Line Number 2, Column 62:<urlset
2
1970
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, either C# or VB.NET, that I can try. Thank You Very Much,
1
1385
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 writing my first transform yesterday and no one at my company knows this stuff.) Assume I have the following XML: <P C="P" O="1" > <E C="P_E1" O="1" W='True'>
3
4243
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 little changed since. However, it works only with an obsolete version of Saxon (6.2.2 I think), and it has a number of small bugs; and I've at last got to the point where I need to fix it. And I'm finding it, frankly, absurdly frustrating and...
0
9685
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9531
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10459
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10237
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7553
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5578
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4120
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3735
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2928
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.