iBatis IsEqual compare multiple values in one tag - ibatis

I'm working on a project with iBatis 2.3. I was wondering if is possible having a multiple value comparison in the same tag.
example:
<isEqual property="test" compareValue="A OR B">
....mySQL...
</isEqual>
<isEqual property="test" compareValue="A AND B">
....mySQL...
</isEqual>
Currently i'm using a list of statements for OR conditions:
<isEqual property="test" compareValue="A">
....mySQL...
</isEqual>
<isEqual property="test" compareValue="B">
....mySQL...
</isEqual>
and nested tags to obtain AND condition,
but the readability is low and is not relly clear the bond between two tags witch are part of the same condition.
Thank you

It would be possible if A and B are in a list, and I guess they aren't. So if you pass A and B as a list parameter you could do the next:
<iterate prepend=”AND” open=”(” close=”)” conjunction=”OR”>
test=#[]#
</iterate>
If not, you need to use different tags, something like next:
<dynamic prepend="where">
< isEqual prepend="and" property="test" compareValue="A">
...
</isEqual>
< isEqual prepend="and" property="test" compareValue="B">
...
</isEqual>
</select>

Related

Get the values from the <xd:doc/>

I want to access the version information which I store in the
<xsl:stylesheet>
<xd:doc scope="stylesheet">
<xd:ul>
<xd:li>
<xd:i>Updates</xd:i>: <xd:ul>
<xd:li>20.11.2018, version: <xd:i>1.1.0</xd:i></xd:li>
<xd:li>08.03.2019, version: <xd:i>2.0.0</xd:i></xd:li>
<xd:li>11.03.2019, version: <xd:i>2.0.1</xd:i></xd:li>
</xd:ul>
</xd:li>
</xd:ul>
</xd:doc>
</xsl:stylesheet>
Normally the XPath of the #select is evaluated to the xml-file which is currently transforming. But how refer XPath to the (main) XSL-stylesheet?
Another option would be to use fn:doc(). But I want to place the version-writing-functionality in an external module, so there will be dynamic file names and I don't know how to get the xsl-file name
I use oXygen XML editor 20.1 where I define the transformation scenarios.
#MartinHonnen Thank you. I updated the code in the question. As you may see I store the version in the docs of the stylesheet.
The document('') / doc('') was what I needed. So I implemented the following:
I put the document-node of the main stylesheet in the variable which is placed in this stylesheet:
<xsl:variable name="currentStylesheet" select="doc('')"/>
then refer to it in the external module
<xsl:variable as="xs:string" name="versionXSLT" select="$currentStylesheet//xd:li[xd:i = 'Updates']/xd:ul/xd:li[last()]/xd:i/string()"/>
I also use it to get the name of the stylesheet:
<xsl:variable as="xs:string" name="currentStylesheetName" select="tokenize(document-uri($currentStylesheet), '/')[last()]"/>
Are there maybe better solutions?

use lxml to get value from from child with parent having a given value

I am new to using lxml with python, and I am having trouble parsing and xml file the way I want. I have searched around and can't seem to find anything that explains this well. What I need to do is iterate though child elements underneath a parent with a fixed value.
For example: I need to loop through all elements under the name "variable", but only underneath the station with id ="VTBRA".
<station id="VTBRA" name="RT 7 Brandon" elev="407" lat="43.76728" lon="-73.05017" distance="" provider="VTRANS">
<ob time="16 Feb 7:30 am EST">
<variable var="T" description="Temp" unit="F" value="9"/>
<variable var="RH" description="Relh" unit="%" value="81"/>
<variable var="FF" description="Wind" unit="mph" value="1"/>
<variable var="DD" description="Direction" unit="deg" value="85"/>
<variable var="DDCARD" description="Wind Card" unit="direction" value="E"/>
<variable var="FFGUST" description="Gust" unit="mph" value="4"/>
<variable var="VV" description="Visibility" unit="miles" value="3.68"/>
<variable var="STAQUAL" description="Station Quality" unit="" value="OK"/>
I am currently modify a code snippit like this:
for elt in node.getiterator('station'):
provider=elt.get('provider','Unknown')
for elt in node.getiterator('variable'):
if elt.get('var', 'Unknown') == "T":
print elt.get('value','Unknown')
This code loops through all instances of "variable" both inside and outside of the station with the id of "VTBRA". Is there a argument or something that can be added to get iterator to only loop through the variable tags underneath the selected station id? Or should I be a different function entirely?
Any help is much appreciated!
Thanks!
You can use the xpath() function to select the <station> element with VTBRA as id and traverse all its <variable> elements, like:
from lxml import etree
import sys
tree = etree.parse(sys.argv[1])
for v in tree.xpath('//station[#id="VTBRA"]//variable'):
## Do whatever you want with each "variable" element. In this case I print its
## "var" attribute.
print(v.get('var'))
Run it like:
python3 script.py xmlfile
That yields (after fixing your non-wellformed xml data):
T
RH
FF
DD
DDCARD
FFGUST
VV
STAQUAL

"Could not get the type info from component xml schema" when loading a page in SiteEdit 2009

I enabled inline editing on SitEdit 2009 SP2 using the answer given here
How do I enable inline field editing in SiteEdit when using an XSLT TBB?
but I keep getting this error when loading the resulting page in SiteEdit:
Sys.FormatException: Could not get the type info from component xml schema.
Field: cf_tcm:20-33457-64_content_header
XPath: [1]
My XSLT TBB fragment:
<xsl:if test="//*[local-name()='content_header'] != ''">
<h1>
<div>
<tcdl:ComponentField name="content_header" index="0">
<xsl:value-of select="//*[local-name()='content_header']">
</tcdl:ComponentField>
</div>
</h1>
</xsl:if>
The output in the published file:
<h1>
<div>
<span>
<!-- Start SiteEdit Component Field: {"ID" : "cf_tcm:20-33457-64_content_header", "XPath" : "[1]", "IsMultiValued" : false} -->
<tcdl:ComponentField name="content_header" index="0" SiteEditProcessed="true">
Test
</tcdl:ComponentField>
</span>
</div>
</h1>
What is wrong with my code?
That error message means that the XPath in your <!-- Start SiteEdit Component Field: { ...} --> command does not point to a field in the current Component. Given that your XPath shows up as [1], that sounds pretty accurate.
You'll need to find the cause of the empty XPath being output. In your XSLT you mark the field with a <tcdl:ComponentField> wrapper. This wrapper is later processed by the "Enable Inline Editing" TBB to generate a corresponding <!-- Start SiteEdit Component Field ... --> command. Since the SiteEdit front-end needs an XPath to the field and the tcdl:ComponentField only contains the field name, the TBB will need to look up the XPath based on the field name.
The "Enable Inline Editing" TBB from SiteEdit 2009 looks up the current Component when processing tcdl:ComponentField by looking at the current resolved item (engine.PublishingContext.ResolvedItem.Item.Id). It then looks up the field in that Component to determine its XPath.
If you look at the package in the Template Builder, what is the Component at the bottom of the Package list? Does that Component contain a content_header field?

ibatis - where to place the <cacheModel> tag?

I have the map config file like this
<sqlMap ..............>
<alias>
<typeAlias ......../>
</alias>
<statements>
....
<sql>....</sql>
<select cacheModel="cache-select-all">....</select>
<update>...</update>
<procedure>...</procedure>
.....
</statements>
<parameterMaps>
<parameterMap>....</parameterMap>
</parameterMaps>
<cacheModel id="cache-select-all" type="LRU" readOnly="true" serialize="false">
<flushInterval hours="24"/>
<flushOnExecute statement="InsertIOs"/>
<!--<property name="CacheSize" value="1000"/>-->
</cacheModel>
</sqlMap>
I am using ibatis (.net, if that matters) and i have one question: where to place the tags? is There a or because placing it like i did, in the statements seems not to work. What am i doing wrong?
You must reference the cacheModel you defined inside a statement tag as shown in the following link:
http://ibatis.apache.org/docs/dotnet/datamapper/ch03s08.html
Before you use it in the select statement. Order does matter here. Otherwise sql map parser wouldn't be able to validate your sql map.

how to insert html tag inside sql in Liquibase migration?

I need to update my data that have html tag inside so wrote this on liquibase
<sql> update table_something set table_content = " something <br/> in the next line " </sql>
it apparently doesn't work on liquibase ( i got loooong errors .. and meaningless). I tried to remove <br/> and it works.
my question is, is it possible to insert / update something that contains xml tag in Liquibase ?
I am using liquibase 1.9.3 with Grails 1.1.1
edited: forgot to set code sample tag in my examples.
As the liquibase author mentions here you'll need to add CDATA section inside <sql>.
In your particular example that would become:
<sql><![CDATA[ update table_something set table_content = " something <br/> in the next line " ]]></sql>
Even better not to use a <sql> tag at all (I added the where clause ...):
<changeSet author="author" id="table_something_1">
<update tableName="table_something">
<column name="table_content"><![CDATA[ something <br/> in the next line ]]></column>
<where>id=1</where>
</update>
<rollback />
</changeSet>

Resources