Trying to print out node values in XSLT using variable elements names?

Yup, FailedDev is right. Someone would write it for you.

Yup, FailedDev is right. Someone would write it for you: , Bit of explanation. The xsl:for-each is gonna select each element in the current rfb2_item for which the local name is contained in the outputElements parameter, or for which the outputElements parameter is * (which would always yield true if that's the case).

It's then gonna sort those based on the length of the substring that goes before that local name in outputElements. Since this value becomes higher when the name occurs later in that parameter, this results in ordering based on your parameter. Example: element VALDATE would yield FUND_ID,SEC_ID for the substring-before function, which in turn would yield 14 as string length.

This is higher than the 8 that you'd get for SEC_ID, meaning the VALDATE value is ordered after SEC_ID. After the xsl:sort, we're simply using xsl:value-of to output the element value. You might want to trim extraneous whitespace there.

Finally, we're testing if the position is not equal to that of the last node in the current context (which is that of xsl:for-each after sorting) and if so, output a comma. This avoids outputting a comma after the last value. The line break I've inserted using xsl:text assumes the Windows/DOS convention.

Remove the if the file should only use new line characters for line breaks, instead of carriage return + new line. Note that this does not escape commas in your CSV output! I'll leave that up to you.It could be interesting to look into using extension functions for delegating this task to Java if it proves too difficult in XSLT/XPath.

This is great, and it works. You just relieved a great deal of stress, thank you. I added at the top of the style sheet to remove all white space.

I did have a few questions. Is the sorting necessary? And the comments you made about string length have me concerned, do I need to consider that if 2 or more elements are of the same length, as in rfb2_item/E1 and rfb2_item/E2?

– RaffiM Nov 9 at 19:32 @RaffiM The sorting is there to make sure the output fields are in the order determined by your parameter, as I believe was one of the requirements. The string length that is checked is that of a substring if the parameter, not the content of the element being output. It's a trick to make sure the elements are output in the order specified in the parameter.

Basically, the name of each element that must be output (FUND_ID, VALDATE...) will yield a different number. Those numbers establish an ordering based on the given parameter. – G_H Nov 9 at 19:38 @G_H...that makes sense...one last question, we're trying to integrate your code into a larger style sheet and it's generating strange results.

We know it works standalone, but the issue is in the way we're calling it. If we invoke your template (using xsl:call-template) from another template that's already matched on "/*", what would change in your template code to produce the same output? – RaffiM Nov 9 at 20:30 @RaffiM xsl:call-template is for named templates.

Mine uses input matching. You'd either need to change my template to a named one and call it with a rfb2_item node as context, or use xsl:apply-templates with a selection that targets those nodes. – G_H Nov 9 at 10:05.

Sometimes in this kind of situation it's worth looking at the possibility of generating or modifying XSLT code using XSLT. You can take the parameterization a lot further that way - for example controlling which fields are output, how they are sorted, whether they are grouped, selection criteria for which rows are selected, etc etc.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions