Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 15th, 2007, 09:43 AM
Registered User
 
Join Date: May 2007
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default Appending set of elements after the similar nodes

Hi again,

I have two files and want to insert some elements in the file2 just after the similar set of elements in the file1. That is in the following two files I need to insert the element <ActorType> in the file2 just after the last <ActorType> element in file1 (I just want the output file to have similar nodes grouped together). Please note that I am copying some other elements from file2 to file 1 at the same time. I can insert this at the end as it is mentioned in the answer to my previous posting but this time I want the new elements to be copied just after the similar elements in the file1.




file1:

<rdf:RDF --goes here>
<SomeOtherElementsGoHere/>
<ActorType rdf:ID="xx"/>
<ActorType rdf:ID="xy"/>
<ActorType rdf:ID="xz"/>
<Transaction rdf:ID="vi34+vi94">
    <Exchanges rdf:ID="ve107">
           <hasEventTypes>
            <TransferType rdf:ID="vp94">
            <isEventType rdf:datatype="http://www.w3.org/2001/XMLSchema#string">decrement</isEventType>
        </TransferType>
    </hasEventTypes>
    <hasEventTypes>
        <TransferType rdf:ID="vp29">
            <ActorType rdf:resource="rightUsers"/>
            <isEventType rdf:datatype="http://www.w3.org/2001/XMLSchema#string">increment</isEventType>
            </TransferType>
        </hasEventTypes>
    </Exchanges>
</Transaction>
<Transaction rdf:ID="vi345+vi945">
    <Exchanges rdf:ID="ve1075">
           <hasEventTypes>
            <TransferType rdf:ID="vp945">
            <isEventType rdf:datatype="http://www.w3.org/2001/XMLSchema#string">decrement</isEventType>
        </TransferType>
    </hasEventTypes>
    <hasEventTypes>
        <TransferType rdf:ID="vp295">
            <ActorType rdf:resource="rightUsers"/>
            <isEventType rdf:datatype="http://www.w3.org/2001/XMLSchema#string">increment</isEventType>
            </TransferType>
        </hasEventTypes>
    </Exchanges>
</Transaction>
</rdf:RDF>

file2:

<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<ConversionType rdf:ID="TransmittingMusicStream">
  <hasTransferedOrConversedResourceType rdf:resource="#MusicStream"/>
  <isEventType rdf:datatype="http://www.w3.org/2001/XMLSchema#string">decrement</isEventType>
  <hasConversedFeature rdf:resource="OnAir"/>
  <hasActorType rdf:resource="#RightUsers"/>
</ConversionType>
<ConversionType rdf:ID="GettingListenerAttention">
  <hasTransferedOrConversedResourceType rdf:resource="#Attention"/>
  <isEventType rdf:datatype="http://www.w3.org/2001/XMLSchema#string">increment</isEventType>
  <hasConversedFeature rdf:resource="BeingPopularRadioStation"/>
  <hasActorType rdf:resource="#RightUsers"/>
</ConversionType>
<ActorType rdf:ID="pq"/>
<ActorType rdf:ID="pr"/>
</rdf:RDF>

 
Old May 15th, 2007, 09:58 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

It seems to me that you need to study the answers to your previous questions until you understand why the solutions work. You will then be able to use this knowledge to find the solutions to other similar problems. There's no point in my helping you with your coding problems if you can't use the answers to increase your understanding and become more proficient.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old May 15th, 2007, 10:16 AM
Registered User
 
Join Date: May 2007
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ok I can reply for that. First I must tell you that your first answer helped me a lot to proceed and thereafter I used it to find solutions to my next couple of problems (So don't worry I am improving myself). To solve my problem in this case I tried to go through the following-sibling axis as I understand I should paste the new nodes following to the similar nodes in the file1. I am using your XSLT 2.0 book and still stuck in finding the proper way to access the following-sibling::Actortype. My specific question is how should I do that? I tried to write another template rule:

<xsl:template match="following-sibling::Actortype" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
                                        xmlns:owl="http://www.w3.org/2002/07/owl#"
                                        xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#">
          <xsl:copy>
          <xsl:apply-templates/>
          <xsl:copy-of select="@*"/>
          <xsl:copy-of select="$file2/*/ActorType"/>
        </xsl:copy>
    </xsl:template>

But it fails as it might be wrong to specify the context node in this way. So can you help me by just giving a clue how I should try?






Similar Threads
Thread Thread Starter Forum Replies Last Post
Appending set of elements at the end sesath XSLT 4 May 15th, 2007 08:10 AM
Appending child nodes to a RDF/OWL file using xslt sesath XSLT 2 May 10th, 2007 04:37 AM
Reading similar elements with different content frankstar XSLT 1 July 7th, 2006 01:38 PM
Grouping orphan nodes to paranet elements ROCXY XSLT 2 January 1st, 2006 07:11 AM
Appending new nodes inside tables in IE 6 stephen_c_ Javascript How-To 1 January 26th, 2005 05:06 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.