Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

xslt: trouble with nested for each statement and concatenation

Posted on 2009-04-24
7
Medium Priority
?
533 Views
Last Modified: 2013-11-18
I'm having trouble with some nested for each statements and concatenation. See my input and xslt below. Everything's fine except the nested foreach and concat portions. How do I fix this? I need to concatenate PrestoURL# and PrestoURLNote#s to form complete links. See the xslt snippet and xml input below. I've attached the complete xslt as well.
xslt:
<xsl:for-each select="inm:PrestoURL1[string(.)] | inmr0:PrestoURL1[string(.)]">
<PropertyValue name="Link1">
<xsl:value-of select="concat( '&lt;A href=&quot;http://prestohost08.inmagic.com', .,'&quot; target=&quot;_blank&quot;&gt;')"/>
<xsl:for-each select="/inm:Results/inm:Recordset/inm:Record/inm:PrestoURLNote1[string(.)] | inmr0:PrestoURLNote1[string(.)]">
<xsl:value-of select="concat(.,'&lt;/A&gt;')"/>
</xsl:for-each>
</PropertyValue>
</xsl:for-each>
<xsl:for-each select="inm:PrestoURL2[string(.)] | inmr0:PrestoURL2[string(.)]">
<PropertyValue name="Link2">
<xsl:value-of select="concat( '&lt;A href=&quot;http://prestohost08.inmagic.com', .,'&quot; target=&quot;_blank&quot;&gt;')"/>
<xsl:for-each select="/inm:Results/inm:Recordset/inm:Record/inm:PrestoURLNote2[string(.)] | inmr0:PrestoURLNote2[string(.)]">
<xsl:value-of select="concat(.,'&lt;/A&gt;')"/>
</xsl:for-each>
</PropertyValue>
</xsl:for-each>
<xsl:for-each select="inm:PrestoURL3[string(.)] | inmr0:PrestoURL3[string(.)]">
<PropertyValue name="Link3">
<xsl:value-of select="concat( '&lt;A href=&quot;http://prestohost08.inmagic.com', .,'&quot; target=&quot;_blank&quot;&gt;')"/>
<xsl:for-each select="/inm:Results/inm:Recordset/inm:Record/inm:PrestoURLNote3[string(.)] | inmr0:PrestoURLNote3[string(.)]">
<xsl:value-of select="concat(.,'&lt;/A&gt;')"/>
</xsl:for-each>
</PropertyValue>
</xsl:for-each>
 
+++++++++++++++++++++++++++++
 
input: 
<?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?>
<inm:Results productTitle="Inmagic CS/TextWorks" productVersion="11.00" xmlns:inm="http://www.inmagic.com/webpublisher/query">
<inm:Recordset setCount="1170">
<inm:Record setEntry="1">
<inm:CatID>603</inm:CatID>
<inm:CatCallNumber />
<inm:CatTitle>ACUHO-I 2000-2001 Salary Survey</inm:CatTitle>
<inm:CatSubtitle />
<inm:CatAlternateTitle />
<inm:CatAuthor>ACUHO-I</inm:CatAuthor>
<inm:CatCorporateAuthor />
<inm:CatResponsibility />
<inm:CatEditor />
<inm:CatEdition />
<inm:CatSource />
<inm:CatPlace>Columbus, OH</inm:CatPlace>
<inm:CatPublisher>ACUHO-I</inm:CatPublisher>
<inm:CatDatePublished>2001</inm:CatDatePublished>
<inm:CatPhysDesc />
<inm:CatSeries />
<inm:CatSubjects>Staff recruitment and retention</inm:CatSubjects>
<inm:CatSubjects>Staff benefits</inm:CatSubjects>
<inm:CatAbstract />
<inm:CatNotes>paper copy held in library</inm:CatNotes>
<inm:CatISBN />
<inm:CatISSN />
<inm:CatLanguage />
<inm:CatRecordType />
<inm:CatStatus />
<inm:CatLocation />
<inm:CatLCCard />
<inm:CatSerFrequency />
<inm:CatSerIssuesPerVol />
<inm:CatSerHoldings>2001</inm:CatSerHoldings>
<inm:CatSerSpecialIssues />
<inm:CatSerIndexedIn />
<inm:CatSerRetention />
<inm:CatURL />
<inm:CatUrlNotes />
<inm:CatImage />
<inm:CatFileName />
<inm:CatFullText />
<inm:CatDateCataloged />
<inm:CatDateApproved />
<inm:CatDateCreated>08/01/06</inm:CatDateCreated>
<inm:CatDateModified>08/01/06</inm:CatDateModified>
<inm:CatMyAnalytics />
<inm:CatMyCompany />
<inm:CatMyGMD />
<inm:CatMyCopyrighted />
<inm:CatCategory>Staff Salary &amp; Job Descriptions</inm:CatCategory>
<inm:CatCreatedBy>cbarnett</inm:CatCreatedBy>
<inm:CatHowCreated>cbarnett</inm:CatHowCreated>
<inm:PrestoMainFile />
<inm:PrestoAddnlFile />
<inm:Count />
<inm:Batch />
<inm:PrestoURL1>\inmagicgenie\ToCImageFolder\2006\08\01salarysurveyp.58-71.pdf</inm:PrestoURL1>
<inm:PrestoURL2>\inmagicgenie\ToCImageFolder\2006\08\01salarysurveyp.72-81.pdf</inm:PrestoURL2>
<inm:PrestoURL3>\inmagicgenie\ToCImageFolder\2006\08\01salarysurveyp.82-98.pdf</inm:PrestoURL3>
<inm:PrestoURL4>\inmagicgenie\ToCImageFolder\2006\08\01Salarysurveyp.99-115.pdf</inm:PrestoURL4>
<inm:PrestoURL5>\inmagicgenie\ToCImageFolder\106\08\/Volumes/ANDREA/01salarysurveyp116-126.pdf</inm:PrestoURL5>
<inm:PrestoURL6>\inmagicgenie\ToCImageFolder\106\08\/Volumes/ANDREA/01salarysurvey127-141.pdf</inm:PrestoURL6>
<inm:PrestoURL7>\inmagicgenie\ToCImageFolder\106\08\/Volumes/ANDREA/01salarysurvey142-150.pdf</inm:PrestoURL7>
<inm:PrestoURL8 />
<inm:PrestoURL9>\inmagicgenie\ToCImageFolder\2006\08\01salarysurveyp1-15.pdf</inm:PrestoURL9>
<inm:PrestoURL10>\inmagicgenie\ToCImageFolder\106\08\/Volumes/ANDREA/01salarysurveyp.16-30.pdf</inm:PrestoURL10>
<inm:PrestoURL11>\inmagicgenie\ToCImageFolder\106\08\/Volumes/ANDREA/01salarysurveyp31-43.pdf</inm:PrestoURL11>
<inm:PrestoURL12>\inmagicgenie\ToCImageFolder\106\08\/Volumes/ANDREA/01salarysurveyp.44-57.pdf</inm:PrestoURL12>
<inm:PrestoURL13 />
<inm:PrestoURL14 />
<inm:PrestoURL15 />
<inm:PrestoURL16 />
<inm:PrestoURL17 />
<inm:PrestoURL18 />
<inm:PrestoURL19 />
<inm:PrestoURL20 />
<inm:PrestoURLNote1>Salary Survey pages 58-71</inm:PrestoURLNote1>
<inm:PrestoURLNote2>Salary Survey pages 72-81</inm:PrestoURLNote2>
<inm:PrestoURLNote3>Salary Survey pages 82-98</inm:PrestoURLNote3>
<inm:PrestoURLNote4>Salary Survey pages 99-115</inm:PrestoURLNote4>
<inm:PrestoURLNote5>Salary Survey pages 116-126</inm:PrestoURLNote5>
<inm:PrestoURLNote6>Salary Survey pages 127-141</inm:PrestoURLNote6>
<inm:PrestoURLNote7>Salary Survey pages 142-150</inm:PrestoURLNote7>
<inm:PrestoURLNote8 />
<inm:PrestoURLNote9>Salary Survey pages 1-15</inm:PrestoURLNote9>
<inm:PrestoURLNote10>Salary Survey pages 16-30</inm:PrestoURLNote10>
<inm:PrestoURLNote11>Salary Survey pages 31-43</inm:PrestoURLNote11>
<inm:PrestoURLNote12>Salary Survey pages 44-57</inm:PrestoURLNote12>
<inm:PrestoURLNote13 />
<inm:PrestoURLNote14 />
<inm:PrestoURLNote15 />
<inm:PrestoURLNote16 />
<inm:PrestoURLNote17 />
<inm:PrestoURLNote18 />
<inm:PrestoURLNote19 />
<inm:PrestoURLNote20 />
</inm:Record>
<inm:Record setEntry="2">
<inm:CatID>1332</inm:CatID>
<inm:CatCallNumber />
<inm:CatTitle>The Praxis of Poverty:</inm:CatTitle>
<inm:CatSubtitle />
<inm:CatAlternateTitle />
<inm:CatAuthor>Orio, Julie</inm:CatAuthor>
<inm:CatAuthor>Ranck, Lorrie</inm:CatAuthor>
<inm:CatCorporateAuthor />
<inm:CatResponsibility />
<inm:CatEditor />
<inm:CatEdition />
<inm:CatSource />
<inm:CatPlace>Dallas, Texas</inm:CatPlace>
<inm:CatPublisher />
<inm:CatDatePublished>2008</inm:CatDatePublished>
<inm:CatPhysDesc>PowerPoint, 13 slides.</inm:CatPhysDesc>
<inm:CatSeries>2008 Living-Learning Conference</inm:CatSeries>
<inm:CatSubjects>Service Learning</inm:CatSubjects>
<inm:CatSubjects>Living learning programs</inm:CatSubjects>
<inm:CatAbstract />
<inm:CatNotes>This presentation explains the context in which the LLC is situated; the theme (poverty) of the LLC and the ways in which the community approached the theme.</inm:CatNotes>
<inm:CatISBN />
<inm:CatISSN />
<inm:CatLanguage />
<inm:CatRecordType>PowerPoint</inm:CatRecordType>
<inm:CatStatus />
<inm:CatLocation />
<inm:CatLCCard />
<inm:CatSerFrequency />
<inm:CatSerIssuesPerVol />
<inm:CatSerHoldings>October 26, 2008</inm:CatSerHoldings>
<inm:CatSerSpecialIssues />
<inm:CatSerIndexedIn />
<inm:CatSerRetention />
<inm:CatURL />
<inm:CatUrlNotes />
<inm:CatImage />
<inm:CatFileName />
<inm:CatFullText />
<inm:CatDateCataloged />
<inm:CatDateApproved />
<inm:CatDateCreated>11/25/08</inm:CatDateCreated>
<inm:CatDateModified />
<inm:CatMyAnalytics />
<inm:CatMyCompany />
<inm:CatMyGMD />
<inm:CatMyCopyrighted />
<inm:CatCategory>Specialized Housing</inm:CatCategory>
<inm:CatCreatedBy />
<inm:CatHowCreated>somebody</inm:CatHowCreated>
<inm:PrestoMainFile />
<inm:PrestoAddnlFile />
<inm:Count />
<inm:Batch />
<inm:PrestoURL1>\inmagicgenie\ToCImageFolder\2008\11\4.5.ppt</inm:PrestoURL1>
<inm:PrestoURL2 />
<inm:PrestoURL3 />
<inm:PrestoURL4 />
<inm:PrestoURL5 />
<inm:PrestoURL6 />
<inm:PrestoURL7 />
<inm:PrestoURL8 />
<inm:PrestoURL9 />
<inm:PrestoURL10 />
<inm:PrestoURL11 />
<inm:PrestoURL12 />
<inm:PrestoURL13 />
<inm:PrestoURL14 />
<inm:PrestoURL15 />
<inm:PrestoURL16 />
<inm:PrestoURL17 />
<inm:PrestoURL18 />
<inm:PrestoURL19 />
<inm:PrestoURL20 />
<inm:PrestoURLNote1>PowerPoint</inm:PrestoURLNote1>
<inm:PrestoURLNote2 />
<inm:PrestoURLNote3 />
<inm:PrestoURLNote4 />
<inm:PrestoURLNote5 />
<inm:PrestoURLNote6 />
<inm:PrestoURLNote7 />
<inm:PrestoURLNote8 />
<inm:PrestoURLNote9 />
<inm:PrestoURLNote10 />
<inm:PrestoURLNote11 />
<inm:PrestoURLNote12 />
<inm:PrestoURLNote13 />
<inm:PrestoURLNote14 />
<inm:PrestoURLNote15 />
<inm:PrestoURLNote16 />
<inm:PrestoURLNote17 />
<inm:PrestoURLNote18 />
<inm:PrestoURLNote19 />
<inm:PrestoURLNote20 />
</inm:Record>
<inm:Record setEntry="3">
<inm:CatID>1333</inm:CatID>
<inm:CatCallNumber />
<inm:CatTitle>The &apos;Greenhouse&apos; Takes Root:</inm:CatTitle>
<inm:CatSubtitle />
<inm:CatAlternateTitle />
<inm:CatAuthor>Denton, Michael</inm:CatAuthor>
<inm:CatCorporateAuthor />
<inm:CatResponsibility />
<inm:CatEditor />
<inm:CatEdition />
<inm:CatSource />
<inm:CatPlace>Dallas, Texas</inm:CatPlace>
<inm:CatPublisher />
<inm:CatDatePublished>2008</inm:CatDatePublished>
<inm:CatPhysDesc>PDF, 36p.</inm:CatPhysDesc>
<inm:CatSeries>2008 Living-Learning Conference</inm:CatSeries>
<inm:CatSubjects>First-year students</inm:CatSubjects>
<inm:CatSubjects>academic success</inm:CatSubjects>
<inm:CatAbstract />
<inm:CatNotes>This presentation discusses how to design a program from assessment data; examines different approaches for assessing residential academic initiatives; and explains the challenges and successes of creating significant change in residential programs.</inm:CatNotes>
<inm:CatISBN />
<inm:CatISSN />
<inm:CatLanguage />
<inm:CatRecordType>PDF</inm:CatRecordType>
<inm:CatStatus />
<inm:CatLocation />
<inm:CatLCCard />
<inm:CatSerFrequency />
<inm:CatSerIssuesPerVol />
<inm:CatSerHoldings>October 27, 2008</inm:CatSerHoldings>
<inm:CatSerSpecialIssues />
<inm:CatSerIndexedIn />
<inm:CatSerRetention />
<inm:CatURL />
<inm:CatUrlNotes />
<inm:CatImage />
<inm:CatFileName />
<inm:CatFullText />
<inm:CatDateCataloged />
<inm:CatDateApproved />
<inm:CatDateCreated>11/25/08</inm:CatDateCreated>
<inm:CatDateModified>11/25/08</inm:CatDateModified>
<inm:CatMyAnalytics />
<inm:CatMyCompany />
<inm:CatMyGMD />
<inm:CatMyCopyrighted />
<inm:CatCategory>Specialized Housing</inm:CatCategory>
<inm:CatCreatedBy>someperson</inm:CatCreatedBy>
<inm:CatHowCreated>otherperson</inm:CatHowCreated>
<inm:PrestoMainFile />
<inm:PrestoAddnlFile />
<inm:Count />
<inm:Batch />
<inm:PrestoURL1>\inmagicgenie\ToCImageFolder\2008\11\Denton_Michael_5.5_Greenhouse_LLC_Final.pdf</inm:PrestoURL1>
<inm:PrestoURL2 />
<inm:PrestoURL3 />
<inm:PrestoURL4 />
<inm:PrestoURL5 />
<inm:PrestoURL6 />
<inm:PrestoURL7 />
<inm:PrestoURL8 />
<inm:PrestoURL9 />
<inm:PrestoURL10 />
<inm:PrestoURL11 />
<inm:PrestoURL12 />
<inm:PrestoURL13 />
<inm:PrestoURL14 />
<inm:PrestoURL15 />
<inm:PrestoURL16 />
<inm:PrestoURL17 />
<inm:PrestoURL18 />
<inm:PrestoURL19 />
<inm:PrestoURL20 />
<inm:PrestoURLNote1>PDF</inm:PrestoURLNote1>
<inm:PrestoURLNote2 />
<inm:PrestoURLNote3 />
<inm:PrestoURLNote4 />
<inm:PrestoURLNote5 />
<inm:PrestoURLNote6 />
<inm:PrestoURLNote7 />
<inm:PrestoURLNote8 />
<inm:PrestoURLNote9 />
<inm:PrestoURLNote10 />
<inm:PrestoURLNote11 />
<inm:PrestoURLNote12 />
<inm:PrestoURLNote13 />
<inm:PrestoURLNote14 />
<inm:PrestoURLNote15 />
<inm:PrestoURLNote16 />
<inm:PrestoURLNote17 />
<inm:PrestoURLNote18 />
<inm:PrestoURLNote19 />
<inm:PrestoURLNote20 />
</inm:Record>
</inm:Recordset>
</inm:Results>

Open in new window

xslt.txt
0
Comment
Question by:GessWurker
  • 4
  • 3
7 Comments
 
LVL 19

Expert Comment

by:zc2
ID: 24230266
Is not the problem only because the XSLT  refers to missed namespace 'inmr0' ?
0
 

Author Comment

by:GessWurker
ID: 24230268
It's not missing. Look at the attached xslt and you'll find:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:inm="http://www.inmagic.com/webpublisher/query"
xmlns:inmr0="http://www.inmagic.com/webpublisher/schemas/Textbase_recordset">
0
 
LVL 19

Accepted Solution

by:
zc2 earned 2000 total points
ID: 24230342
I see at least one problem - more then one closing "/A" concatenation. Is that you mean?
It occurs because you do not specify from which record you are taking the PrestoURLNote#
To fix it you can add a variable wit current record number, like
<xsl:variable name="rec-num" select="position()"/>
and use it in the expressions:
<xsl:for-each select="/inm:Results/inm:Recordset/inm:Record[$rec-num]/inm:PrestoURLNote1[string(.)] | inmr0:PrestoURLNote1[string(.)]">

Honestly, I found your code kinda ponderous. It hard to advise not knowing what it suppose to do, but I guess, there is a lot what can be improved.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:GessWurker
ID: 24230394
Yes, I'm getting the extra closing /a. That may be the biggest problem. However, I'm not sure how to execute your suggestion.
0
 
LVL 19

Expert Comment

by:zc2
ID: 24230428
Declare the xsl:variable I mentioned right after
<xsl:for-each select="inm:Record"> element (i.e. in the line 13)

In each XPath expression where you need to access only the elements of the _current_ inm:Record, use the variable value in the squared brackets.
Or, you can put to the variable the reference to the current inm:Record, like
<xsl:variable name="cur-record" select="."/>

, and them use it as follows:

<xsl:for-each select="$cur-record/inm:PrestoURLNote1[string(.)] | inmr0:PrestoURLNote1[string(.)]">

0
 

Author Comment

by:GessWurker
ID: 24230582
Perfect. Thanks for your help!
0
 

Author Comment

by:GessWurker
ID: 24230587
...even if you did call the code ponderous...

;)
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface In the first article: A Better Website Login System (http://www.experts-exchange.com/A_2902.html) I introduced the EE Collaborative Login System and its intended purpose. In this article I will discuss some of the design consideratio…
Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

578 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question