Search code examples
xsltslowcheetah

XMLNS attribute removed by Slow Cheetah transformation


I'm trying to use Slow Cheetah to transform a Windows scheduled task config file. I'm simply trying to add "repetition" node information, like so:

ORIGINAL:

<Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
  <RegistrationInfo>
    <Date>2013-01-02T09:32:12.2196371</Date>
    <Author>xxx</Author>
  </RegistrationInfo>
  <Triggers>
    <CalendarTrigger>
      <StartBoundary>2013-01-10T01:00:00</StartBoundary>
      <Enabled>true</Enabled>
      <ScheduleByDay>
        <DaysInterval>1</DaysInterval>
      </ScheduleByDay>
    </CalendarTrigger>
  </Triggers>
.....
</Task>

REQUIRED, ADDITIONAL XML

<CalendarTrigger>
   <Repetition>
     <Interval>PT300S</Interval>
   </Repetition>
</CalendarTrigger>

To do this, I have the following transformation file:

<?xml version="1.0" encoding="utf-16" ?>
<Task version="1.2">
  <Triggers>
    <CalendarTrigger xdt:Transform="Insert">
      <Repetition>
        <Interval>PT300S</Interval>
      </Repetition>
    </CalendarTrigger>
  </Triggers>
</Task>

The problem I'm having is that all attributes outside of the CalendarTrigger node are removed (and therefore making the resultant transformation config an invalid scheduled task format).

I have tried adding

xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform" xdt:Transform="SetAttributes" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task"

to the Task node, but the attribute is then generated at CalendarTrigger level (and I cannot put this attribute on the original, because I then get "No element in the source document matches '/Task/Triggers' ").

Any pointers?

UPDATE:

The problem seems to be isolated to the xmlns attribute; if I try to include this in the 'Task' node of the original, I get "No element in the source document matches '/Task/Triggers'" - BUT changing this attribute to 'xmlns2' works fine and produces exactly what I need (albeit with an 'xmlns2' attribute!). Is this a known limitation of Slow Cheetah? Anyone know of a potential work-around?


Solution

  • That's because your xdt:Transform="Insert" is one level to high.

    This should work:

    <?xml version="1.0" encoding="utf-16" ?>
    <Task xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
        <Triggers>
          <CalendarTrigger>
            <Repetition xdt:Transform="Insert">
              <Interval>PT300S</Interval>
            </Repetition>
          </CalendarTrigger>
        </Triggers>
    </Task>