[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
RE: [xsl] Concat values
Subject: RE: [xsl] Concat values From: "M. David Peterson" <m.david@xxxxxxxxxx> Date: Mon, 12 Apr 2004 10:21:25 -0600 |
I started to look at your code and decided it would probably be better to take your description of what you are trying to do and show you a sample solution as opposed to actually trying work through your code and adjust it as needed. If the following code doesn't help with better understanding how to create a solution that will work for you let me know and Ill take another look at the actual code... But in this particular case you've got the value of a variable that needs to be compared to the value of an attribute in a sequence of elements that have matched a certain XPath statement... So if we start there and move forward then I think we should still be on the page... So heres our variable... <xsl:variable name="attName" value="someValue"/> And heres is where we are going to compare that variables values with an attribute of each element that matches our XPath criteria. But first we create a token element just so that we are sticking to a set of good coding standards. Then within that element we can create an attribute with the proper name. To cap off this portion of the code we are going to select the items we are desirous to test against our variables value and if they pass the test we are going to use the all mighty power of xsl:apply-templates to send our little golden children away to be buffed and shined and transformed into objects of shear beauty. So this code... <xsl:element name="proudParentof_ExtendedAttributeDefinitionObjectLink"> <xsl:attribute name="ExtendedAttributeDefinitionObjectLink"> <xsl:apply-templates select="Frustrated_Child_of_ ExtendedAttributeDefinitionObjectLink[@compareMeTOattName = $attName]"/> </xsl:attribute> <xsl:element> <xsl:template match=" Frustrated_Child_of_ ExtendedAttributeDefinitionObjectLink"> <xsl:text> | </xsl:text><xsl:value-of select="."/> </xsl:template> Is going to give us this output... <proudParentof_ExtendedAttributeDefinitionObjectLink ExtendedAttributeDefinitionObjectLink=" | child_1 | child_2 | child_3"/> Of which of course is invalid given the | to the left of child_1. So to fix that you would need to pass a parameter(well call it "pos" for simplicity's sake) along with the apply-templates that contains the value of its position() and then uses <xsl:if test="$pos > 1"><xsl:text> | </xsl:text></xsl:if> to ensure that the first match to the template doesn't get the | stuck in front of him/her. So, if we put all the above together then we would have something that looks like this... <xsl:template match="/"> <xsl:element name="proudParentof_ExtendedAttributeDefinitionObjectLink"> <xsl:attribute name="ExtendedAttributeDefinitionObjectLink"> <xsl:apply-templates select="Frustrated_Child_of_ ExtendedAttributeDefinitionObjectLink[@compareMeTOattName = $attName]"> <xsl:with-param name="pos" select="position()"/> </xsl:apply-templates> </xsl:attribute> <xsl:element> </xsl:template> <xsl:template match=" Frustrated_Child_of_ ExtendedAttributeDefinitionObjectLink"> <xsl:param name="pos"/> <xsl:if test="$pos > 1"><xsl:text> | </xsl:text></xsl:if><xsl:value-of select="."/> </xsl:template> and this would give you the following output: <proudParentof_ExtendedAttributeDefinitionObjectLink ExtendedAttributeDefinitionObjectLink="child_1 | child_2 | child_3"/> which should be similar to the output you are looking for and will hopefully save your CPU a cycle or 12 as well :) Hope this helps! Best regards, <M:D/> -----Original Message----- From: James Paul [mailto:jpaul@xxxxxxxxxxx] Sent: Monday, April 12, 2004 9:26 AM To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx Subject: [xsl] Concat values What I am trying to do is based on a value $attrName I need to check every line item to see if this value exist in that Line Item. If it does exist for a particular line item I need to get the value of the line item and pass it back and concatenate it with a | under a particular attribute. Hence I should produce something like this: ExtendedAttributeDefinitionObjectLink="LineItem1|LineItem2|LineItem3" Where are the Line Item names with a matching $attrName gets appended to the Attribute above. <xsl:attribute name = "ExtendedAttributeDefinitionObjectLink"> <xsl:variable name="GroupLineItems" /> I Loop through the line items here... <xsl:for-each select="../../../../../ListOfRequestQuoteDetails/RequestQuoteDetails"> <xsl:variable name="LineItem"> I call the template below looping through the Reference of the Line Item <xsl:apply-templates select="RequestQuoteItemDetail/BaseItemDetail/ListOfItemReferences/ListO fReferenceCoded/ReferenceCoded" mode="BidLineItems"> Passing the template the value I have to match on. <xsl:with-param name="fieldName" select="$attrName"/> </xsl:apply-templates> </xsl:variable> Trying to concatenate... but of course this will not work <xsl:variable name="GroupLineItems" select="concat($LineItem,'|')" /> </xsl:for-each> <xsl:value-of select="$GroupLineItmes" /> </xsl:attribute> My Template is below <xsl:template match="ReferenceCoded" mode="BidLineItems"> <xsl:param name="fieldName"/> <xsl:if test="ReferenceTypeCodedOther='QuestBidExtendedAttribute'"> <xsl:if test="PrimaryReference/Reference/RefNum=$fieldName"> <xsl:value-of select="SupportingReference/Reference/RefNum"/> </xsl:if> </xsl:if> </xsl:template> Thanks... James
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Concat values, James Paul | Thread | RE: [xsl] Concat values, Andreas L. Delmelle |
[xsl] Comment nodes in XSLT files., Greg Alvord | Date | RE: [xsl] Concat values, Andreas L. Delmelle |
Month |
Keywords