views:

56

answers:

2

Hi There, I'm trying to write an XSLT transformation which will replace the value in one node with the value of it's preceding sibling. Then return the entire document transformed :)

Find the occurrences of

<package:packageDownloadLocator>http://myunwantedurl&lt;/package:packageDownloadLocator&gt;

and replace with the text value of it's proceeding sibling

<package:packagePreviewLocator>http://myurl.com&lt;/package:packagePreviewLocator&gt;

Thanks for any help or suggestions

Note: The node to be found does not always exist in each record.

From this:

    <?xml version="1.0"?>
<SRW:searchRetrieveResponse xmlns:SRW="http://www.loc.gov/zing/srw/" xmlns:DIAG="http://www.loc.gov/zing/srw/diagnostics" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:package="info:srw/extension/13/package-v1.0">
<SRW:records>
<SRW:record>
   <SRW:recordData>
    <dc:dc>
     <dc:title xml:lang="en">Opportunities for involvement for service users and carers at the Open University in Scotland</dc:title>
     <dc:description xml:lang="en">Booklet explaining the different ways service users or carers can assist</dc:description>
     <dc:publisher>Open University</dc:publisher>
     <dc:format>application/pdf</dc:format>
     <dc:type>Narrative Text</dc:type>
     <dc:rights xml:lang="en">Copyright Open University, 2009</dc:rights>
     <dc:subject>health and health care, health care, nursing</dc:subject>
    </dc:dc>
   </SRW:recordData>
   <SRW:extraRecordData>
    <package:packagePreviewLocator>http://myurl.com&lt;/package:packagePreviewLocator&gt;
    <package:packageDownloadLocator>http://myunwantedurl&lt;/package:packageDownloadLocator&gt;
    <record:record xmlns:record="http://srw.o-r-g.org/schemas/rec/1.0/"&gt;
     <record:lastModified>2009-09-29</record:lastModified>
     <record:created>2009-09-29</record:created>
    </record:record>
   </SRW:extraRecordData>
  </SRW:record>
 </SRW:records>
</SRW:searchRetrieveResponse>

To this:

<?xml version="1.0"?>
<SRW:searchRetrieveResponse xmlns:SRW="http://www.loc.gov/zing/srw/" xmlns:DIAG="http://www.loc.gov/zing/srw/diagnostics" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:package="info:srw/extension/13/package-v1.0">
<SRW:records>
<SRW:record>
   <SRW:recordData>
    <dc:dc>
     <dc:title xml:lang="en">Opportunities for involvement for service users and carers at the Open University in Scotland</dc:title>
     <dc:description xml:lang="en">Booklet explaining the different ways service users or carers can assist</dc:description>
     <dc:publisher>Open University</dc:publisher>
     <dc:format>application/pdf</dc:format>
     <dc:type>Narrative Text</dc:type>
     <dc:rights xml:lang="en">Copyright Open University, 2009</dc:rights>
     <dc:subject>health and health care, health care, nursing</dc:subject>
    </dc:dc>
   </SRW:recordData>
   <SRW:extraRecordData>
    <package:packagePreviewLocator>http://myurl.com&lt;/package:packagePreviewLocator&gt;
    <package:packageDownloadLocator>http://myurl.com&lt;/package:packageDownloadLocator&gt;
    <record:record xmlns:record="http://srw.o-r-g.org/schemas/rec/1.0/"&gt;
     <record:lastModified>2009-09-29</record:lastModified>
     <record:created>2009-09-29</record:created>
    </record:record>
   </SRW:extraRecordData>
  </SRW:record>
 </SRW:records>
</SRW:searchRetrieveResponse>
A: 

Read up on the "Identity Transformation" (Google it, there's a good page at Wikipedia). All you need is an identity transform plus a template that matches the tag you want to change. You'll also have to decide if you want any preceding sibling, or a specific preceding tag (and what to do if there's no preceding sibling).

Jim Garrison
Will do thanks Jim
atomicjeep
+1  A: 
Dimitre Novatchev
atomicjeep