[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: searching for occurrences of unique string-value a
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? On Thu, Jun 5, 2008 at 3:52 PM, Michael M|ller-Hillebrand <mmh@xxxxxxxxxxxxx> wrote: > > I hope I got your case correct, with the help of wonderful Kernow (http://kernowforsaxon.sf.net/) and its XSLT playground I get this result (after completing the XML and after making the separate guids in the XML more verbose: > > Using a key is a good idea. I do not understand what you mean with a sub-node, try this: > > <xsl:key name="targetFile" match="File" use=".//CuHistoryGuid/text()"/> > > <xsl:template match="RelatedLinks/CuRef"> > <a class="old" href="{@CuHistoryGuid}.html"> > <xsl:apply-templates/> > </a> > <a class="new" href="{key('targetFile', @CuHistoryGuid)/FileGuid/text()}.html"> > <xsl:apply-templates/> > </a> > </xsl:template> > > The key "targetFile" indexes all elements File according to the text content of their descendant "CuHistoryGuid". > > You may also notice the use of AVT (Attribute Value Templates = expressions in {} used in attribute values) to make the code more readable. It should work with XSLT 1.0, although I tested only with 2.0. > > HTH, > > - Michael > > Am 05.06.2008 um 20:08 schrieb Julie: > >> I've searched the archives, but I either haven't found anything that >> would help with this or I haven't recognized what I should be looking >> for! >> >> What I have is an xml publication file that contains a list of File >> elements. Each of these File elements outputs a different html file. >> Within the html files there are optional related links. We use the >> CuHistoryGuid element to identify these related links, the number for >> which is generated dynamically by the database. Unfortunately, the >> original programmer of our application agreed that these guids would >> become the output filename and in fact they are not. Instead there is >> another guid, generated by the File element, that is used as the >> filename. What I need to do is use the stylesheet to search for the >> unique value of the CuHistoryGuid, find it elsewhere in the file and >> then go UP to the corresponding FileGuid and replace the value with >> that. I was looking at using the key function, but it requires a >> sub-node (if I understand it correctly) rather than an ancestor node. >> Is there another way to accomplish this? >> >> The xml looks roughly like this: >> >> <PublicationContent> >> >> <File> >> <FileGuid>944f983d-110f-4d08-9c69-1e9f019228ac</FileGuid> >> <FileShortDescription>Help 1</FileShortDescription> >> <ContentUnit> >> <CuMetadata> >> <BinaryType>no</BinaryType> >> <CuHistoryGuid>CuHistoryGuid</CuHistoryGuid> >> </CuMetadata> >> <CuContent> >> <Task> >> <RelatedLinks> >> <CuRef >> CuHistoryGuid="072aea44-573d-43b6-8a64-5cbd1ffccea8">Related link >> text</CuRef> >> </RelatedLinks> >> (content, etc....) >> </ContentUnit> >> </File> >> >> >> >> <File> >> <FileGuid>e47267b0-7167-4cfd-a4c1-18dbb3a33b4d</FileGuid> >> <FileShortDescription>Help 2</FileShortDescription> >> <ContentUnit> >> <CuMetadata> >> <BinaryType>no</BinaryType> >> >> <CuHistoryGuid>072aea44-573d-43b6-8a64-5cbd1ffccea8</CuHistoryGuid> >> (etc.) >> >> >> >> Current template in xsl file: >> >> <xsl:template match="RelatedLinks/CuRef"> >> <a class="rt"> >> <xsl:attribute name="href"> >> <xsl:value-of select="@CuHistoryGuid"/><xsl:text>.html</xsl:text> >> </xsl:attribute> >> <xsl:apply-templates/> >> </a> >> </xsl:template> >> >> >> >> output is: >> >> <p class="RelatedLinks"> >> <a class="rt" >> href="072aea44-573d-43b6-8a64-5cbd1ffccea8.html">Link Text</a> >> </p> >> >> >> >> Want the output to be: >> >> <p class="RelatedLinks"> >> <a class="rt" >> href="e47267b0-7167-4cfd-a4c1-18dbb3a33b4d8.html">Link Text</a> >> </p> >> >> >> where the href equals the FileGuid for the file to which I want to link. >> >> >> >> The CuRef element contains the CuHistoryGuid for which I would be >> searching outside of this particular File element, but within the same >> PublicationContent element. >> >> >> >> I am using xmlspy , so their processor (but am definitely willing to >> change to 2.0, this is just where we were when we started the >> project): >> >> XML Spy 2008 sp 2 (Enterprise edition) >> >> XSL version: 1 >> >> Vendor: Altova GmbH >> >> Vendor URL: http://www.altova.com >> >> Thanks for any help! >> >> Julie > > > -- > _______________________________________________________________ > Michael M|ller-Hillebrand: Dokumentations-Technologie > Adobe Certified Expert, FrameMaker > Lvsungen und Training, FrameScript, XML/XSL, Unicode > <http://cap-studio.de/> -- Tel. +49 (9131) 28747
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|