xsl-list
[Top] [All Lists]

Re: [xsl] naive identity transform question

2006-11-20 17:18:06
I suspect that your problem is you get the generated child but lose
the parent?   :o)

if so, use:
 <xsl:copy>
     <xsl:element
name="sourceDate"><xsl:text>0000-00-00</xsl:text></xsl:element>
 </xsl:copy>

You probably would also want to produce the child in the necessary
namespace... This is not done neither in your code nor in the code
above.


--
Cheers,
Dimitre Novatchev
---------------------------------------
Truly great madness cannot be achieved without significant intelligence.
---------------------------------------
To invent, you need a good imagination and a pile of junk
-------------------------------------
You've achieved success in your field when you don't know whether what
you're doing is work or play




On 11/20/06, Jon Crump <jjcrump(_at_)u(_dot_)washington(_dot_)edu> wrote:
I'm sure this is a very straightforward task, but I'm missing something
fundamental about the identity transformation.

I want to copy an xml file exactly except if nodeX lacks a childY write
element Y.

The consensus on the identity transform suggested something like this:

xsl file identity.xsl

  <xsl:template match="node()|@*">
      <xsl:copy>
          <xsl:apply-templates select="@*|node()"/>
      </xsl:copy>
  </xsl:template>

xsl file intended transformation.xsl

  <xsl:import href="identity.xsl"/>

  <xsl:template match="//snotes:SourceNote[not(snotes:sourceDate)]">
      <xsl:element 
name="sourceDate"><xsl:text>0000-00-00</xsl:text></xsl:element>
  </xsl:template>

IE: copy all elements complete, except where //snotes:SourceNote has no
snotes:sourceDate child. In that case, write a snotes:sourceDate element
with the value 0000-00-00.

Anyone willing to point out the obvious to the naive?

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>