How do I fix xslt if condition?
Questions about XML that are not covered by the other forums should go here.
-
- Posts: 62
- Joined: Thu Jun 26, 2014 9:00 pm
How do I fix xslt if condition?
I have a simple xml document. I want to check if UserID is not equal to IntegrationAdmin or Integration_Admin
My xslt is
Here is the sample xml document
Expected result
However my code is return nothing.
Here is the xslt that is not processing as I expect it to The problem is the if statement with or. Can someone help me?
My xslt is
Here is the sample xml document
Code: Select all
<Integration xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:tsg="http://tsgweb.com" xmlns:IXML="http://tsgweb.com" xmlns="">
<ControlPoint Timestamp="7/2/2019 2:30:42 PM" UserID="Deuua">SAVE-PR-EVENT</ControlPoint>
<CaseEvent xmlns:reslib="urn:reslib" Date="06/14/2019" ID="252945065" InternalEventID="1851137353">
<EventType Word="NOPERWELL">Personal Well-being Report [R]</EventType>
</CaseEvent>
<CaseEvent xmlns:reslib="urn:reslib" Date="06/14/2019" ID="252945066" InternalEventID="1851137354">
<EventType Word="NORIGHTS">Annual Notice of Rights [R]</EventType>
</CaseEvent>
</Case>
<IntegrationConditions>
<IntegrationCondition Word="TRUE" Description="Always True">
<ControlPoint Timestamp="7/2/2019 2:30:42 PM" UserID="Deuua">SAVE-PR-EVENT</ControlPoint>
</IntegrationCondition>
</IntegrationConditions>
</Integration>
Code: Select all
<NotificationEvent notificationType="MMGUpdate" elementState="Add" elementName="CaseEvent" elementKey="252945069">InsertPWBRorAOS</NotificationEvent>
However my code is return nothing.
Here is the xslt that is not processing as I expect it to The problem is the if statement with or. Can someone help me?
Code: Select all
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" encoding="UTF-8" omit-xml-declaration="yes"/>
<xsl:template match="/">
<xsl:if test="Integration/ControlPoint='SAVE-PR-EVENT'">
<xsl:apply-templates select="Integration/Case/CaseEvent"/>
</xsl:if>
</xsl:template>
<xsl:template match="CaseEvent">
<xsl:if test="((//Integration/ControlPoint/@UserID!='IntegrationAdmin') or (//Integration/ControlPoint/@UserID!='Integration_Admin'))">
<xsl:if test="(@Op='E') and ((EventType/@Word='NOPERWELL') or (EventType/@Word='NORIGHTS'))">
<NotificationEvent notificationType="MMGUpdate">
<xsl:attribute name="elementState">Add</xsl:attribute>
<xsl:attribute name="elementName">CaseEvent</xsl:attribute>
<xsl:attribute name="elementKey"><xsl:value-of select="@ID"/></xsl:attribute>
<xsl:text>InsertPWBRorAOS</xsl:text>
</NotificationEvent>
</xsl:if>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
-
- Posts: 9431
- Joined: Fri Jul 09, 2004 5:18 pm
Re: How do I fix xslt if condition?
Hi,
So an xsl:if like this:
means that the "Op" attribute must be set to "E" AND either the "Word" attribute is set to "NOPERWELL" or "NORIGHTS".
So as you are missing the "Op='E'" attribute on the "CaseEvent" element, the xsl:if condition is not fulfilled.
Regards,
Radu
So an xsl:if like this:
Code: Select all
<xsl:if test="(@Op='E') and ((EventType/@Word='NOPERWELL') or (EventType/@Word='NORIGHTS'))">
So as you are missing the "Op='E'" attribute on the "CaseEvent" element, the xsl:if condition is not fulfilled.
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
<oXygen/> XML Editor
http://www.oxygenxml.com
-
- Posts: 62
- Joined: Thu Jun 26, 2014 9:00 pm
Re: How do I fix xslt if condition?
I think I had posted wrong xml document. Here is the correct xml document code
Code: Select all
<Integration xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:tsg="http://tsgweb.com" xmlns="">
<ControlPoint Timestamp="7/2/2019 3:38:03 PM" UserID="IntegrationAdmin">SAVE-PR-EVENT</ControlPoint>
<Case xmlns:user="http://tylertechnologies.com" InternalID="1625030039" ID="18482188">
<CaseEvent xmlns:reslib="urn:reslib" Op="E" Date="06/14/2019">
<EventType Word="NOPERWELL">Personal Well-being Report [R]</EventType>
</CaseEvent>
</Case>
<IntegrationConditions>
<IntegrationCondition Word="TRUE" Description="Always True">
<ControlPoint Timestamp="7/2/2019 3:38:03 PM" UserID="Deea">SAVE-PR-EVENT</ControlPoint>
</IntegrationCondition>
</IntegrationConditions>
</Integration>
-
- Posts: 62
- Joined: Thu Jun 26, 2014 9:00 pm
Re: How do I fix xslt if condition?
I think my solution is this
<xsl:if test="((/Integration/ControlPoint/@UserID!='Integration_Admin') and (/Integration/ControlPoint/@UserID!='IntegrationAdmin'))">
I should not use the word or between the two conditions.
<xsl:if test="((/Integration/ControlPoint/@UserID!='Integration_Admin') and (/Integration/ControlPoint/@UserID!='IntegrationAdmin'))">
I should not use the word or between the two conditions.
Return to “General XML Questions”
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