![]() |
|
#1
|
|||
|
|||
|
XSLT & for-each
I have an xml file that is 500 lines. I can do other XSLT operations on it fine, but when I try to do a for-each for an element that appears twice, I get no result. Is there a problem with for-each and large ( ? ) files or does the fault lie in the xml file. I know it's a tough q to ask without including the XML file but it's too long to attach / contains confidential info.
Here is the code I'm using: Code:
<xsl:for-each select="/resources/ADT_A03/OBX"> <xsl:variable name="OBX" select="OBX.3-Observation_Identifier/CE.1-identifier"/> <xsl:choose> <xsl:when test="matches($OBX, 'AMB_ARRVL_DT') "> <xsl:element name="F_ambarrivedate"> <xsl:value-of select="OBX.5-Observation_Value/TS.1"/> </xsl:element> </xsl:when> <xsl:when test="matches($OBX, 'AMBTRNCAREDT') "> <xsl:element name="F_ambxcaredate"> <xsl:value-of select="OBX.5-Observation_Value/TS.1"/> </xsl:element> </xsl:when> </xsl:choose> </xsl:for-each> Last edited by kb19; 11-06-2009 at 03:25 PM. |
| Sponsored Links |
|
#2
|
|||
|
|||
|
If only the input xml is shown, we could give a solution. You need not show the whole xml, you can give just a snippet related to the code, with some dummy data. Try giving it.
|
|
#3
|
|||
|
|||
|
I don't think 500 lines is large and even if you process large documents then you are more likely to run out of memory than to encounter problems with wrong results.
Of course an XSLT processor is some software that like all software can have bugs; if you want to rule out a bug as the cause of the problem then consider to try a second XSLT processor. You seem to use XSLT 2.0 so the choice of XSLT processors is not that large but with Saxon 9, AltovaXML tools and Gestalt there is some choice. If your XML has confidential data you can't show then, if you need help fixing the problem with your XSLT, you need to edit the XML and replace any confidential data with some dummy data. It shouldn't be too difficult to construct a small sample showing us in what way "an element ... appears twice" leads to problems. |
|
#4
|
|||
|
|||
|
Some xslt-processors won't allow you to redeclare the same variable.
so instead of declaring <xsl:variable name="OBX" select="OBX.3-Observation_Identifier/CE.1-identifier"/> just use OBX.3-Observation_Identifier/CE.1-identifier where you use $OBX and see if that works. If it doesn't, we realy need more information about the input. Code:
<xsl:for-each select="/resources/ADT_A03/OBX">
<xsl:choose>
<xsl:when test="matches(OBX.3-Observation_Identifier/CE.1-identifier, 'AMB_ARRVL_DT') ">
<F_ambarrivedate><xsl:value-of select="OBX.5-Observation_Value/TS.1"/></F_ambarrivedate>
</xsl:when>
<xsl:when test="matches(OBX.3-Observation_Identifier/CE.1-identifier, 'AMBTRNCAREDT') ">
<F_ambxcaredate><xsl:value-of select="OBX.5-Observation_Value/TS.1"/></F_ambxcaredate>
</xsl:when>
</xsl:choose>
</xsl:for-each>
Stefaan |
![]() |
| Thread Tools | |
| Display Modes | |
|
|