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

XSL -XML to XSL reorienting node

Subject: XSL -XML to XSL reorienting node
From: Mike Ferrando <mikeferrando@xxxxxxxxx>
Date: Thu, 27 Jun 2002 09:33:49 -0700 (PDT)
node xsl
Friends,
I have been fuzting around with this for a while and I am close but
still no cigar. (I don't smoke, but you know what I mean.)

What I have got is an XML document that has a very deep (6-8 levels)
hierarchy.  These levels are relevant to the data, but the data nodes
are very homogeneous (all music scores). I would just reproduce them
but I need to do things to each of these wrapper nodes (adding bells
and whistles, etc.). Instead of trying to write templates for all
these levels, I decided to write a stylesheet that transforms my XML
document into a stylesheet of templates.

Of course the key is to exclude the stylesheet from writing a
template for each of the data children nodes. When I did this the
first problem was that when the stylesheet found an excluded child
and it stopped and reoriented itself to the next major node (though
it was about 4 nodes deep when it was found). I thought it would go
to the next following sibling node. I figured that I needed to write
a loop to reorient the processing node to the following-sibling when
the current child was an excluded node. But my loop is not working.

What I am wondering is why I cannot seem to exclude the children
nodes and still get the parent nodes when I reorient my
apply-templates.

Could someone give me a hint?

Sincerely,
Mike Ferrando
Washington, DC

XSL:
This is the xsl without the reorient node loop written in. It stops
when it reaches an unwanted child.

<xsl:template match="node()[not(SCRGRP | SCRGRPX | NON-SCORE |
SCORE)]">
  <xsl:variable name="ta">xsl</xsl:variable>
  <xsl:variable name="tb">template</xsl:variable>
  <xsl:variable name="bbb" select="concat($ta, ':', $tb)"/>
  <xsl:variable name="atb">apply-templates</xsl:variable>
  <xsl:variable name="apply" select="concat($ta, ':', $atb)"/>
    <xsl:if test="child::*">
      <xsl:choose>
        <xsl:when test="name()=''">
        </xsl:when>
        <xsl:otherwise>
          <xsl:element name="{$bbb}">
            <xsl:attribute name="match">
              <xsl:value-of select="name()"/>
            </xsl:attribute>
              <xsl:element name="{$apply}">
                <xsl:attribute name="select">
                  <!-- <xsl:call-template name="check"/> -->
                  <xsl:value-of select="name(child::*)"/>
                </xsl:attribute>
              </xsl:element>
          </xsl:element>
        </xsl:otherwise>
      </xsl:choose>
</xsl:if>
<xsl:apply-templates select="node()[not(SCRGRP | SCRGRPX | NON-SCORE
| SCORE)]"/>
</xsl:template>

XSL:
This is the same xsl but I wrote in the reoreintation loop (which
doesn't work).

<xsl:template match="node">
  <xsl:variable name="ta">xsl</xsl:variable>
  <xsl:variable name="tb">template</xsl:variable>
  <xsl:variable name="bbb" select="concat($ta, ':', $tb)"/>
  <xsl:variable name="atb">apply-templates</xsl:variable>
  <xsl:variable name="apply" select="concat($ta, ':', $atb)"/>
    <xsl:if test="child::*()[not(SCRGRP | SCRGRPX | NON-SCORE |
SCORE)]">
      <xsl:choose>
        <xsl:when test="name()=''">
        </xsl:when>
        <xsl:otherwise>
          <xsl:element name="{$bbb}">
            <xsl:attribute name="match">
              <xsl:value-of select="name()"/>
            </xsl:attribute>
              <xsl:element name="{$apply}">
                <xsl:attribute name="select">
                  <!-- <xsl:call-template name="check"/> -->
                  <xsl:value-of select="name(child::*)"/>
                </xsl:attribute>
              </xsl:element>
          </xsl:element>
        </xsl:otherwise>
      </xsl:choose>
</xsl:if>
<xsl:choose>
<xsl:when test="child::*[not(NON-SCORE | SCRGRP | SCRGRPX | SCORE)]">
<xsl:apply-templates select="node()"/>
</xsl:when>
<xsl:otherwise>
	<xsl:apply-templates select="following-sibling::*[1]"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>

XML:
This is the part of the schema of my document.

<?xml version="1.0" encoding="utf-8"?>
<schema>
   <element name="NEWLAND_ZEUNER_COLLECTION" occurs="1">
- <element name="VOCAL_MUSIC" occurs="1">
- <element name="Sacred_vocal_music__Latin" occurs="1">
- <element name="Masses_-_Printed_music" occurs="1">
- <element name="SCRGRP" occurs="9">
  <element name="C100_C" occurs="9" /> 
- <element name="SCORE" occurs="9">
  <element name="CT" occurs="9" /> 
- <element name="TP" occurs="9">
  <element name="S" occurs="2" /> 
  </element>
  <element name="PL" occurs="6" /> 
  <element name="PB" occurs="7" /> 
  <element name="C1007" occurs="10" /> 
  <element name="DT" occurs="2" /> 
  </element>
  </element>
- <element name="OTHER_MUSIC" occurs="1">
- <element name="SCORE" occurs="3">
  <element name="CT" occurs="3" /> 
  <element name="TP" occurs="3" /> 
  <element name="C1007" occurs="2" /> 
  </element>
  </element>
  </element>
- <element name="Masses_-_Manuscripts" occurs="1">
- <element name="SCRGRP" occurs="46">
  <element name="C100_C" occurs="46" /> 
- <element name="SCORE" occurs="79">
  <element name="CT" occurs="79" /> 
- <element name="TM" occurs="79">
  <element name="S" occurs="1" /> 
  <element name="DT" occurs="6" /> 
  </element>
  <element name="C1007" occurs="73" /> 
  <element name="C1011" occurs="5" /> 
- <element name="C1009" occurs="5">
  <element name="LISTHEAD" occurs="5" /> 
  <element name="ITEM" occurs="18" /> 
  </element>
  </element>
  </element>
- <element name="OTHER_MUSIC" occurs="1">
- <element name="SCORE" occurs="4">
  <element name="CT" occurs="4" /> 
  <element name="TM" occurs="3" /> 
  <element name="C1007" occurs="2" /> 
  <element name="TO" occurs="1" /> 
  </element>
  </element>
  </element>




__________________________________________________
Do You Yahoo!?
Yahoo! - Official partner of 2002 FIFA World Cup
http://fifaworldcup.yahoo.com

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


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.