xsl-list
[Top] [All Lists]

[xsl] RE: xsl-list Digest 19 Oct 2006 05:10:00 -0000 Issue 932

2006-10-19 07:18:44
Date: Wed, 18 Oct 2006 09:17:20 -0400
To: <xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com>
From: "McDonald, Shaun" <Shaun(_dot_)McDonald(_at_)jetblue(_dot_)com>
Subject: FW: 2 XML Files, 1 XSLt Output to HTML
Message-ID:
<7734A3BCC1D3654BAE325601D4DD05090162784A(_at_)FSCEVS03(_dot_)jetblue(_dot_)com>

In case anyone is working on a solution to the problem presented in my
last post, I thought it only proper to inform you that I have
discovered
an answer.  It follows:
=20

<xsl:template match=3D"n1:share">

   <xsl:variable name=3D"x" select=3D"@item" />

   <xsl:variable name=3D"xx" select=3D"@loc" />

     <xsl:for-each select=3D"document(@loc)">

           <xsl:for-each select=3D"//*[(_at_)id=3D$x]">=20

                 <xsl:value-of select=3D"."/>

           </xsl:for-each>

     </xsl:for-each>

</xsl:template>

-----Original Message-----
From: McDonald, Shaun=20
Sent: Monday, October 16, 2006 6:44 PM
To: 'xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com'
Subject: 2 XML Files, 1 XSLt Output to HTML

Hi,

I am using MSXML 3.0

XML SOURCE NAME: doc1.xml
<Oproc id=3D"right">
      <Para>
              <bold id=3D"ao1">text1</bold>
      </Para>
      <Para id=3D"ao2">text2</Para>
      <Para>
              <Bold id=3D"o3">text3</Bold>
      </Para>
      <Para id=3D"ao4">text4</Para>
      <Para id=3D"ao5">text5</Para>
      <Para id=3D"ao6">text6</Para>
      <Para>
              <Caution id=3D"ao7">text7</Caution>
      </Para>
</Oproc>

XML TARGET NAME: doc2.xml

<Oproc>
      <Para>
              <bold id=3D"ao1">
                      <share loc=3D"source.xml" item=3D"ao1"/>
              </bold>
              <extRef id=3D"getmaster"
href=3D"somedoc.html#idTitle1234"
reflocation=3D"*" refmanual=3D""/>
      </Para>
      <Para id=3D"ao2">
              <share loc=3D"source.xml" item=3D"ao2"/>
      </Para>
      <Para>
              <Bold id=3D"ao3">
                      <share loc=3D"source.xml" item=3D"ao3"/>
              </Bold>
      </Para>
      <Para id=3D"ao4">
              <share loc=3D"source.xml" item=3D"ao4"/>
      </Para>
      <Para id=3D"ao5">
              <share loc=3D"source.xml" item=3D"ao5"/>
      </Para>
      <Para id=3D"ao6">
              <share loc=3D"source.xml" item=3D"ao6"/>
      </Para>
      <Para>
              <Caution id=3D"ao7">
                      <share loc=3D"source.xml" item=3D"ao7"/>
              </Caution>
      </Para>
</Oproc>

XSLT Version 1.0:
<xsl:template match=3D"n1:share">
   <xsl:variable name=3D"x" select=3D"@item" />
   <xsl:variable name=3D"xx" select=3D"@loc" />
   <xsl:for-each select=3D"document(@loc)">
     <xsl:value-of select=3D"current()"/>
   </xsl:for-each>
</xsl:template>

I want,
TARGET: doc2.xml:
<Oproc>
      <Para>
              <bold id=3D"ao1">text1</bold>
              <extRef id=3D"getmaster"
href=3D"somedoc.html#idTitle1234"
reflocation=3D"*" refmanual=3D""/>
      </Para>
      <Para id=3D"ao2">text2</Para>
      <Para>
              <Bold id=3D"ao3">text3</Bold>
      </Para>
      <Para id=3D"ao4">text4</Para>
      <Para id=3D"ao5">text5</Para>
      <Para id=3D"ao6">text6</Para>
      <Para>
              <Caution id=3D"ao7">text7</Caution>
      </Para>
</Oproc>

What I get is,
TARGET: doc2.xml:
<Oproc>
      <Para>
              <bold
id=3D"ao1">text1text2text3text4text5text6text7</bold>
              <extRef id=3D"getmaster"
href=3D"somedoc.html#idTitle1234"
reflocation=3D"*" refmanual=3D""/>
      </Para>
      <Para id=3D"ao2">text1text2text3text4text5text6text7</Para>
      <Para>
              <Bold
id=3D"ao3">text1text2text3text4text5text6text7</Bold>
      </Para>
      <Para id=3D"ao4">text1text2text3text4text5text6text7</Para>
      <Para id=3D"ao5">text1text2text3text4text5text6text7</Para>
      <Para id=3D"ao6">text1text2text3text4text5text6text7</Para>
      <Para>
              <Caution
id=3D"ao7">text1text2text3text4text5text6text7</Caution>
      </Para>
</Oproc>

I inherited these files recently.  From what I have learned, the xslt
is
processing as it should.  I have not, however, been able to figure out
how to get the desired output.

------------------------------

Date: Wed, 18 Oct 2006 19:21:18 +0200
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
From: Abel Braaksma <abel(_dot_)online(_at_)xs4all(_dot_)nl>
Subject: Re: [xsl] 2 XML Files, 1 XSLt Output to HTML
Message-ID: <4536628E(_dot_)7000909(_at_)xs4all(_dot_)nl>

McDonald, Shaun wrote:
XSLT Version 1.0:
<xsl:template match="n1:share">
    <xsl:variable name="x" select="@item" />
    <xsl:variable name="xx" select="@loc" />
    <xsl:for-each select="document(@loc)">
      <xsl:value-of select="current()"/>
    </xsl:for-each>
 </xsl:template>

I want,
TARGET: doc2.xml:
<Oproc>
     <Para>
             <bold id="ao1">text1</bold>
             <extRef id="getmaster" href="somedoc.html#idTitle1234"
reflocation="*" refmanual=""/>
     </Para>


You are using <xsl:value-of> here. Surely that's not what you want. You
don't want the *value* (which returns a string representation of the
nodes in the select expression) but a *copy* of all the nodes. Change
"value-of" to "copy-of" and you are done (it will copy comment nodes
and
processing instructions as well but not the opening xml declaration).

Another little thing, why the for-each? You can remove it and just use:
<xsl:copy-of select="document(@loc)" />

(it is only from xslt 2.0 that document(xx) function can be used on a
sequence and will return multiple documents, in which case the for-each
could make sense)

Cheers,

-- Abel Braaksma
  http://www.nuntia.com

------------------------------

Date: Wed, 18 Oct 2006 19:28:01 +0200
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
From: Abel Braaksma <abel(_dot_)online(_at_)xs4all(_dot_)nl>
Subject: Re: [xsl] FW: 2 XML Files, 1 XSLt Output to HTML
Message-ID: <45366421(_dot_)4060806(_at_)xs4all(_dot_)nl>

McDonald, Shaun wrote:
In case anyone is working on a solution to the problem presented in
my
last post, I thought it only proper to inform you that I have
discovered
an answer.  It follows:


<xsl:template match="n1:share">
    <xsl:variable name="x" select="@item" />
    <xsl:variable name="xx" select="@loc" />
      <xsl:for-each select="document(@loc)">
            <xsl:for-each select="//*[(_at_)id=$x]">
                  <xsl:value-of select="."/>
            </xsl:for-each>
      </xsl:for-each>
</xsl:template>


Aha, I see. Sorry, missed that post, just spotted it. I misunderstood
your question then, sorry.

But there are a few redundancies here. The xsl:for-each is not needed.
And the extra variable 'xx' is not needed either. You can change your
code as follows (less lines, same results)

<xsl:template match="n1:share">
   <xsl:variable name="x" select="@item" />
     <xsl:for-each select="document(@loc)//*[(_at_)id=$x]">
         <xsl:value-of select="."/>
     </xsl:for-each>
</xsl:template>

-- Abel Braaksma
  http://www.nuntia.com

------------------------------


Thank you, Sir, it works well.

FYI, we have since made my target xml less redundant.  Previously the
structure of the target xml was defined by the source in order to
maintain format integrity from source to target.  This method was not
the most efficient.

In this instance, using <xsl:apply-templates select="."/> instead of
<xsl:value-of> allows us to use one target element for all source
elements we want.

So,
<xsl:template match="n1:share">
    <xsl:variable name="x" select="@item" />
      <xsl:for-each select="document(@loc)//*[(_at_)id=$x]">
          <xsl:apply-templates select="."/>
        <p/>
      </xsl:for-each>
  </xsl:template>

Allows target.xml,
<Oproc>
        <Para>
                <share loc="source.xml" item="op"/>
                <----"op" is id value of parent element in source---->
        </Para>
</Oproc>

And returns,
<Oproc id="op">
        <Para>
                <bold id="ao1">text1</bold>
        </Para>
        <Para id="ao2">text2</Para>
        <Para>
                <Bold id="ao3">text3</Bold>
        </Para>
        <Para id="ao4">text4</Para>
        <Para id="ao5">text5</Para>
        <Para id="ao6">text6</Para>
        <Para>
                <Caution id="ao7">text7</Caution>
        </Para>
</Oproc>

Now I'm wondering if I've created more redundancy in the xslt.  Hhmm.

Thanks again!

--~------------------------------------------------------------------
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>
  • [xsl] RE: xsl-list Digest 19 Oct 2006 05:10:00 -0000 Issue 932, McDonald, Shaun <=