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

RE: xsl-list Digest 19 Oct 2006 05:10:00 -0000 Issue 9

Subject: RE: xsl-list Digest 19 Oct 2006 05:10:00 -0000 Issue 932
From: "McDonald, Shaun" <Shaun.McDonald@xxxxxxxxxxx>
Date: Thu, 19 Oct 2006 10:18:18 -0400
getmaster download
>Date: Wed, 18 Oct 2006 09:17:20 -0400
>To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
>From: "McDonald, Shaun" <Shaun.McDonald@xxxxxxxxxxx>
>Subject: FW: 2 XML Files, 1 XSLt Output to HTML
>Message-ID:
<7734A3BCC1D3654BAE325601D4DD05090162784A@xxxxxxxxxxxxxxxxxxxx>
>
>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"//*[@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@xxxxxxxxxxxxxxxxxxxxxx'
>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@xxxxxxxxxxxxxxxxxxxxxx
>From: Abel Braaksma <abel.online@xxxxxxxxx>
>Subject: Re:  2 XML Files, 1 XSLt Output to HTML
>Message-ID: <4536628E.7000909@xxxxxxxxx>
>
>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@xxxxxxxxxxxxxxxxxxxxxx
>From: Abel Braaksma <abel.online@xxxxxxxxx>
>Subject: Re:  FW: 2 XML Files, 1 XSLt Output to HTML
>Message-ID: <45366421.4060806@xxxxxxxxx>
>
>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="//*[@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)//*[@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)//*[@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!

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.