need to use result of for each outside the loop
Here should go questions about transforming XML with XSLT and FOP.
-
- Posts: 1
- Joined: Fri May 24, 2024 1:08 am
need to use result of for each outside the loop
I have a function which uses a for each to find the element desired and return a substring. I assign a variable from within the for-each loop, but I don't know how to make the scope more global, at least within this function. Once this function call returns the field, $lineAllocPct, the main part will use it in calculations.
Thank you,
Code: Select all
<xsl:function name="custom:getAllocPct">
<xsl:param name="allocDetailStr"/>
<xsl:param name="costCenter"/>
<xsl:variable name="lineAllocPct"/>
<xsl:for-each select="$allocDetailStr">
<xsl:if test ="contains($allocDetailStr,$costCenter)">
<xsl:variable name="lineAllocPct" select="normalize-space(substring-after($allocDetailStr,'having'))"/>
<xsl:sequence select="$lineAllocPct"/>
</xsl:if>
</xsl:for-each>
<xsl:sequence select="$lineAllocPct"/>
</xsl:function>
Thank you,
-
- Posts: 102
- Joined: Tue Aug 19, 2014 12:04 pm
Re: need to use result of for each outside the loop
Post by Martin Honnen »
XSLT's for-each is not really a loop.
As for your problem to assign the result of a for-each to a variable, you can do stuff like
On the other hand, it is often not necessary to use for-each/XSLT but you can just select the values with the power of pure XPath.
If you need more help consider to show the sample input data you want to process with your function, a sample function call and the result you expect your function to return. It would also help if you used `as` type declarations on your variables, currently you have parameter called `allocDetailStr`, it is not clear whether it will be a single string and why you then need to or want to use an iteration with for-each over a single string.
As for your problem to assign the result of a for-each to a variable, you can do stuff like
Code: Select all
<xsl:variable name="result" as="item()*">
<xsl:for-each select="$some-sequence">
... <xsl:sequence select="some-xpath-expression"/>
</xsl:for-each>
</xsl:variable>
<xsl:sequence select="$result"/>
If you need more help consider to show the sample input data you want to process with your function, a sample function call and the result you expect your function to return. It would also help if you used `as` type declarations on your variables, currently you have parameter called `allocDetailStr`, it is not clear whether it will be a single string and why you then need to or want to use an iteration with for-each over a single string.
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service