469,890 Members | 1,419 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,890 developers. It's quick & easy.

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 1427


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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Bob | last post: by
8 posts views Thread by Larry Coon | last post: by
4 posts views Thread by J | last post: by
1 post views Thread by Candle | last post: by
3 posts views Thread by Simon Brooke | last post: by
1 post views Thread by Waqarahmed | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.