Go Back   Velocity Reviews > Newsgroups > XML
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

XML - XSLT Conditional creation of destination Node

 
Thread Tools Search this Thread
Old 07-14-2006, 04:03 PM   #1
Default XSLT Conditional creation of destination Node


I'm trying to write an XSLT to convert an XML document from one schema
to
another.

The destination XML schema has an optional State element. The element
can be
left out, but if it's present it must have a two character code. The
source XML has
a required element of type string that be left blank. My problem is,
if the source node is present but blank, I want to NOT create the
destination Date node. If the source node is populated
then I want the destination node create and populated.

How do I do this?

Currently, I seem to always get the destination node and if the source
was
blank, the destination is comming up blank and causing a schema
validation
error.

In case you can't tell... I'm a complete NEWBIE to XSTL.

I'm currently using Altova MapForce 2006 to do the development.

Someone in another news group recommend the following:
---------------------------------------------------------------------------------------------------
<xsl:template match="source-element-name[text()]">
<result-element-name>
<xsl:value-of select="." />
</result-element-name>
</xsl:template>

<xsl:template match="source-element-name(not(text())]" />
---------------------------------------------------------------------------------------------------


But being so new to both XSLT and Altova's MapForce, I have no idea how
I would include such code in my Mapforce mapping.

Any help would be greatly appreciated.



tommalia
  Reply With Quote
Old 07-15-2006, 05:14 AM   #2
Dimitre Novatchev
 
Posts: n/a
Default Re: XSLT Conditional creation of destination Node

Read about, understand and use the >xsl:choose> instruction.

Cheers,
Dimitre Novatchev

"tommalia" <> wrote in message
news: ups.com...
> I'm trying to write an XSLT to convert an XML document from one schema
> to
> another.
>
> The destination XML schema has an optional State element. The element
> can be
> left out, but if it's present it must have a two character code. The
> source XML has
> a required element of type string that be left blank. My problem is,
> if the source node is present but blank, I want to NOT create the
> destination Date node. If the source node is populated
> then I want the destination node create and populated.
>
> How do I do this?
>
> Currently, I seem to always get the destination node and if the source
> was
> blank, the destination is comming up blank and causing a schema
> validation
> error.
>
> In case you can't tell... I'm a complete NEWBIE to XSTL.
>
> I'm currently using Altova MapForce 2006 to do the development.
>
> Someone in another news group recommend the following:
> ---------------------------------------------------------------------------------------------------
> <xsl:template match="source-element-name[text()]">
> <result-element-name>
> <xsl:value-of select="." />
> </result-element-name>
> </xsl:template>
>
> <xsl:template match="source-element-name(not(text())]" />
> ---------------------------------------------------------------------------------------------------
>
>
> But being so new to both XSLT and Altova's MapForce, I have no idea how
> I would include such code in my Mapforce mapping.
>
> Any help would be greatly appreciated.
>



  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump