XML.orgXML.org
FOCUS AREAS |XML-DEV |XML.org DAILY NEWSLINK |REGISTRY |RESOURCES |ABOUT
OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]
Re: [xml-dev] XSTL stylesheet workarounds for exceptions


im new  XML and After reading all the various posts im Extremely Confused. My Company is requesting that i export Data from the DB into xml for Data transfer services. I see alot of Different methods,Elements,Members ect... and Sub queries on Data contained within XML schema. Im in need of exporting data from MsSQL for Plant Production Declarations to our SAP systems. It looks like XML is a whole lot of work Versus just straight Transactions to the source. What is the real Purpose of XML?
Thanks for your Help
Alan Cannon
Process / Automation SCADA Engineer
Plastic Omnium
50 tyger river rd
Duncan, S.C 29344
864 622-3221 (OFFICE)
864 245-6807 (CELL)
Email: acannon@plasticomnium.com
Please consider your environmental responsibility before printing this e-mail



Jack Bush <netbeansfan@yahoo.com.au>

02/02/2009 04:03 PM

To
xml-dev@lists.xml.org
cc
Subject
[xml-dev] XSTL stylesheet workarounds for exceptions





Hi All,

 

I am at a stage of fine-tuning an existing stylesheet that has been worked on recently and would like include some workarounds to accommodate exceptional data in the following 2 areas:

 

( i ) Get the content of sub-elements <a> as follows:

<p>

  <strong>Hobbies:</strong>

  <a shape="rect" href="http://www.hobbies.com/fishing title="Shark Hunting">fishing</a>

  <a shape="rect" href="http://www.hobbies.com/hunting title="Animal">rabbit</a>

(Out-door adventures)

</p>

 

Intended output

<hobbies> fishing<hobbies>

<hobbies> rabbit<hobbies>

 

In this case, it is both fishing, rabbit that I am after. However, I still couldn’t get it working despite having tried numerous of the following stylesheet approaches:

 

<xsl:template match="/">

  <employee>

    <xsl:apply-templates select="//ns:p"/>

  </employee>

</xsl:template>

 

( A ) <xsl:template match="ns:p[ns:strong='Hobbies:']">

         <xsl:copy-of              

           <hobbies>select="ns:a"/></hobbies>

       </xsl:template>

               or

( B ) <xsl:template match="ns:p[ns:strong='Hobbies:']">

         <xsl:for-each select="ns:a/text()[normalize-space() != '']">

           <hobbies><xsl:value-of select="normalize-space()"/></hobbies>

         </xsl:for-each>

       </xsl:template>

               or

( C ) <xsl:template match="ns:p[ns:strong='Hobbies:']">

         <xsl:for-each select=".//ns:a/text()[normalize-space() != '']">

           <hobbies><xsl:value-of select="normalize-space()"/></hobbies>

         </xsl:for-each>

       </xsl:template>

              or

( D ) <xsl:template match="ns:p[ns:strong='Hobbies:']">

         <xsl:for-each select="ns:p/ns:a/text()[normalize-space() != '']">

           <hobbies><xsl:value-of select="normalize-space()"/></hobbies>

         </xsl:for-each>

       </xsl:template>

               or

( E ) <xsl:template match="ns:p[ns:strong='Hobbies:']">

         <xsl:for-each select="../ns:a//text()[normalize-space() != '']">

           <hobbies><xsl:value-of select="normalize-space()"/></hobbies>

         </xsl:for-each>

       </xsl:template>

               or

( F ) <xsl:template match="ns:p[ns:strong='Hobbies:']">

         <xsl:for-each select="ns:a">

          <xsl:for-each select="text()[normalize-space() != '']">"

            <hobbies><xsl:value-of select="normalize-space()"/></hobbies>

          </xsl:for-each>

        </xsl:for-each>

     </xsl:template>

               or

( G ) <xsl:template match="ns:p[ns:strong='Hobbies:']">

          <xsl:for-each select=".//ns:a">

            <xsl:for-each select="text()[normalize-space() != '']">"

              <hobbies><xsl:value-of select="normalize-space()"/></hobbies>

            </xsl:for-each>

          </xsl:for-each>

        </xsl:template>

 

( ii ) I also like to add a default generic value for any missing element. Say if there are no

<p><strong>Hobbies:</strong></p> element in such document, yet I still would like to generate a

null element such as <hobbies>Unknown</hobbies>. The intended stylesheet should look

like the following but again couldn’t get it working still:

 

<xsl:template match="/">

  <employee>

    <xsl:apply-templates select="//ns:p"/>

  </employee>

</xsl:template>

 

<xsl: choose>

  <xsl: when test="ns:p[ns:strong='Hobbies:']">

    <xsl:template match="ns:p[ns:strong='Hobbies:']">

      <xsl:for-each select="text()[normalize-space() != '']">

        <hobbies><xsl:value-of select="normalize-space()"/></hobbies>

      </xsl:for-each>

    </xsl:template>

  </xsl:when>

<xsl:otherwise>

  <hobbies>Unknown</hobbies>

</xsl:otherwise>

</xsl: choose>

 

I have run out of ideas and would be very much appreciated if anyone could give me some suggestion on how to tackle this task.

Jack




Stay connected to the people that matter most with a smarter inbox. Take a look.



[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]


News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 1993-2007 XML.org. This site is hosted by OASIS