xsl-list
[Top] [All Lists]

Re: [xsl] searching for occurrences of unique string-value and replacing with string value of another node

2008-06-06 03:09:54
Am 05.06.2008 um 23:28 schrieb Julie:

Thank you for your reply, Michael.

I put this code in but I do not get a result for the link, just ".html".

I can evaluate the xpath expressions through xmlspy, but this is a
function so that doesn't work...is there any other way to evaluate
what is in the key?


I don't know if that is possible. I'll give you my complete test case, which should work even with XMLSpy ;-)

- Michael Müller-Hillebrand

XML
===

<?xml version="1.0" encoding="UTF-8"?>
<PublicationContent>
   <File>
      <FileGuid>fileguid1</FileGuid>
      <FileShortDescription>Help 1</FileShortDescription>
      <ContentUnit>
         <CuMetadata>
            <BinaryType>no</BinaryType>
            <CuHistoryGuid>cuhistguid1</CuHistoryGuid>
          </CuMetadata>
          <CuContent>
            <Task>
               <RelatedLinks>
                  <CuRef CuHistoryGuid="cuhistguid2">Related link
text</CuRef>
               </RelatedLinks>
            </Task>
         </CuContent>
     </ContentUnit>
  </File>
  <File>
    <FileGuid>fileguid2</FileGuid>
    <FileShortDescription>Help 2</FileShortDescription>
    <ContentUnit>
       <CuMetadata>
          <BinaryType>no</BinaryType>
          <CuHistoryGuid>cuhistguid2</CuHistoryGuid>
       </CuMetadata>
    </ContentUnit>
  </File>
</PublicationContent>

XSLT
====

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
                version="1.0">

<xsl:key name="targetFile" match="File" use=".//CuHistoryGuid/text ()"/>

   <xsl:template match="RelatedLinks/CuRef">
     <a class="old" href="{(_at_)CuHistoryGuid}(_dot_)html">
         <xsl:apply-templates/>
      </a>
<a class="new" href="{key('targetFile', @CuHistoryGuid)/ FileGuid/text()}.html">
         <xsl:apply-templates/>
      </a>
   </xsl:template>
        

    <xsl:template match="@*|node()">
                       <xsl:apply-templates select="@*|node()"/>
   </xsl:template>

</xsl:stylesheet>

Result
======

<?xml version="1.0" encoding="UTF-8"?>
<a class="old" href="cuhistguid2.html"/>
<a class="new" href="fileguid2.html"/>

--
_______________________________________________________________
Michael Müller-Hillebrand: Dokumentations-Technologie
Adobe Certified Expert, FrameMaker
Lösungen und Training, FrameScript, XML/XSL, Unicode
<http://cap-studio.de/> -- Tel. +49 (9131) 28747




--~------------------------------------------------------------------
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>
--~--