[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: unwanted and non prefix namespaces in output

Subject: RE: unwanted and non prefix namespaces in output
From: "Joel Friedman" <jfriedman@xxxxxxxxxxxx>
Date: Sat, 31 Jul 2004 02:08:31 -0400
non prefix
I am very new to xslt (approx 4 hours) but I have managed to (mostly) do
the simple task I am trying to perform.

I am attempting to take an xml file in this format (greatly shortened
for simplicity):

<?xml version="1.0" encoding="utf-16"?>
<sequence version="1" description="foo" command="bar"
xmlns="http://schemas.microsoft.com/ads/2003/sequence">

  <sequence version="1" description="Image" command="WIN2000"
xmlns="http://schemas.microsoft.com/ads/2003/sequence">
    <task>
      <command>foo</command>
      <parameters>
        <parameter>bar</parameter>
      </parameters>
    </task>
   <task>
    ...
   </task
  </sequence>

  <sequence version="1" description="Patch" command="WIN2000"
xmlns="http://schemas.microsoft.com/ads/2003/sequence">
    <task>
      <command>foo</command>
      <parameters>
        <parameter>bar</parameter>
      </parameters>
    </task>
    <task>
     ...
    </task
  </sequence>

  <sequence version="1" description="Patch" command="WIN2K3"
xmlns="http://schemas.microsoft.com/ads/2003/sequence">
    <task>
      <command>foo</command>
      <parameters>
        <parameter>bar</parameter>
      </parameters>
    </task>
   <task>
    ...
   </task
  </sequence>

 <sequence version="1" description="foo" command="bar"
xmlns="http://schemas.microsoft.com/ads/2003/sequence">
   ...
 </sequence>

  ...

</sequence>


And apply this XSL:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"

xmlns:ads="http://schemas.microsoft.com/ads/2003/sequence"
                version="1.0">

  <xsl:output method="xml" indent="yes"/>
  <xsl:variable name="osName"
select="ads:sequence/ads:sequence/@command"/>

  <xsl:template match="/">
    <xsl:apply-templates select="ads:sequence"/>
  </xsl:template>

  <xsl:template match="ads:sequence">
    <xsl:choose>
      <xsl:when test="(@description='Patch')">
        <xsl:if test="@command=$osName">
          <sequence>
            <xsl:apply-templates select="@*|node()"/>
          </sequence>
          </xsl:if>
      </xsl:when>
      <xsl:otherwise>
        <sequence>
          <xsl:apply-templates select="@*|node()"/>
        </sequence>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

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

</xsl:stylesheet>


Basically I'm trying to fetch the OS Name from the command attribute of
the second sequence (fixed location)  Then the if OS matches the command
attribute for the sequence with a description of 'Patch', copy it over.
Also copy over everything else that isn't a Patch sequence.  So
basically my output should be identical to my input minus the Patch
sequence where the OS does not match.  My problem enlies that every
'task ' element has the namespace added to it but the sequence element
does not.

..sample output:

<?xml version="1.0" encoding="UTF-16"?>
<sequence version="1" description="foo" command="bar">

 <sequence version="1" description="Image" command="WIN2000">
  <task  xmlns="http://schemas.microsoft.com/ads/2003/sequence">
   <command>foo</command>
   <parameters>
    <parameter>bar</parameter>
   </parameters>
  </task>


The exclude-result-prefixes="ads" squashed my namespace on the root
sequence element (which I don't want).  I need the namespace to only be
defined on all sequence blocks.  Just like the input.  The logic part of
not copying over the block I do not need does work.  It's probably not
the best way, but it is functional.  Forgive me if I did not use the
correct XSL grammar while trying to explain my problem.

Anybody have an idea of a direction I should look in for a solution?

Thanks in advance,

--Joel

________________________________

From: Joel Friedman
Sent: Saturday, July 31, 2004 2:07 AM
To: 'xsl-list@xxxxxxxxxxxxxxxxxxxxxx'
Subject: unwanted and non prefix namespaces in output


I am very new to xslt (approx 4 hours) but I have managed to (mostly) do
the simple task I am trying to perform.

I am attempting to take an xml file in this format (greatly shortened
for simplicity):

<?xml version="1.0" encoding="utf-16"?>
<sequence version="1" description="foo" command="bar"
xmlns="http://schemas.microsoft.com/ads/2003/sequence">

  <sequence version="1" description="Image" command="WIN2000"
xmlns="http://schemas.microsoft.com/ads/2003/sequence">
    <task>
      <command>foo</command>
      <parameters>
        <parameter>bar</parameter>
      </parameters>
    </task>
   <task>
    ...
   </task
  </sequence>

  <sequence version="1" description="Patch" command="WIN2000"
xmlns="http://schemas.microsoft.com/ads/2003/sequence">
    <task>
      <command>foo</command>
      <parameters>
        <parameter>bar</parameter>
      </parameters>
    </task>
    <task>
     ...
    </task
  </sequence>

  <sequence version="1" description="Patch" command="WIN2K3"
xmlns="http://schemas.microsoft.com/ads/2003/sequence">
    <task>
      <command>foo</command>
      <parameters>
        <parameter>bar</parameter>
      </parameters>
    </task>
   <task>
    ...
   </task
  </sequence>

 <sequence version="1" description="foo" command="bar"
xmlns="http://schemas.microsoft.com/ads/2003/sequence">
   ...
 </sequence>

  ...

</sequence>


And apply this XSL:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"

xmlns:ads="http://schemas.microsoft.com/ads/2003/sequence"
                version="1.0">

  <xsl:output method="xml" indent="yes"/>
  <xsl:variable name="osName"
select="ads:sequence/ads:sequence/@command"/>

  <xsl:template match="/">
    <xsl:apply-templates select="ads:sequence"/>
  </xsl:template>

  <xsl:template match="ads:sequence">
    <xsl:choose>
      <xsl:when test="(@description='Patch')">
        <xsl:if test="@command=$osName">
          <sequence>
            <xsl:apply-templates select="@*|node()"/>
          </sequence>
          </xsl:if>
      </xsl:when>
      <xsl:otherwise>
        <sequence>
          <xsl:apply-templates select="@*|node()"/>
        </sequence>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

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

</xsl:stylesheet>


Basically I'm trying to fetch the OS Name from the command attribute of
the second sequence (fixed location)  Then the if OS matches the command
attribute for the sequence with a description of 'Patch', copy it over.
Also copy over everything else that isn't a Patch sequence.  So
basically my output should be identical to my input minus the Patch
sequence where the OS does not match.  My problem enlies that every
'task ' element has the namespace added to it but the sequence element
does not.

..sample output:

<?xml version="1.0" encoding="UTF-16"?>
<sequence version="1" description="foo" command="bar">

 <sequence version="1" description="Image" command="WIN2000">
  <task  xmlns="http://schemas.microsoft.com/ads/2003/sequence">
   <command>foo</command>
   <parameters>
    <parameter>bar</parameter>
   </parameters>
  </task>


The exclude-result-prefixes="ads" squashed my namespace on the root
sequence element (which I don't want).  I need the namespace to only be
defined on all sequence blocks.  Just like the input.  The logic part of
not copying over the block I do not need does work.  It's probably not
the best way, but it is functional.  Forgive me if I did not use the
correct XSL grammar while trying to explain my problem.

Anybody have an idea of a direction I should look in for a solution?

Thanks in advance,

--Joel

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.