How to update counter in BI Publisher for-each tag - bi-publisher

I have a counter variable: <?xdoxslt:set_variable($_XDOCTX, ‘storeCounter’, 0)?>
I put this counter into a for-each tag and hope that it will return the loop times:
<?for-each:G_1?>
<?xdoxslt:set_variable($_XDOCTX, 'storeCounter', xdoxslt:get_variable($_XDOCTX, 'storeCounter') + 1)?>
Here is my report detail:
and data model xml:
<output rootName="DATA_DS" uniqueRowName="false">
<nodeList name="data-structure">
<dataStructure tagName="DATA_DS">
<group name="G_1" label="G_1" source="test">
<element name="TY_SOH_TOT" value="TY_SOH_TOT" label="TY_SOH_TOT" dataType="xsd:double" breakOrder="" fieldOrder="1"/>
<element name="LY_SOH_TOT" value="LY_SOH_TOT" label="LY_SOH_TOT" dataType="xsd:double" breakOrder="" fieldOrder="2"/>
<element name="LLY_SOH_TOT" value="LLY_SOH_TOT" label="LLY_SOH_TOT" dataType="xsd:double" breakOrder="" fieldOrder="3"/>
</group>
</dataStructure>
</nodeList>
</output>
But it just returns 1 as the result of the counter:
<?xdoxslt:get_variable($_XDOCTX, 'storeCounter')?>
So, how to make the counter updated correctly?

Looking at your new xml, it seems you will have to loop through 'element' instead of 'group'. Looping through 'group' will give you 0.
<?xdoxslt:set_variable($_XDOCTX, 'storeCounter', 0)?>
<?for-each: element?>
<?xdoxslt:set_variable($_XDOCTX, 'storeCounter', xdoxslt:get_variable($_XDOCTX, 'storeCounter') + 1)?>
<?end for-each?>
<?xdoxslt:get_variable($_XDOCTX, 'storeCounter')?>
Will give you 3.

Have you closed the for loop ?
<?for-each:G_1?>
<?xdoxslt:set_variable($_XDOCTX, 'storeCounter', xdoxslt:get_variable($_XDOCTX, 'storeCounter') + 1)?>
<?end for-each?>
<?xdoxslt:get_variable($_XDOCTX, 'storeCounter')?>
Prints the count.
If you just need the count, you can use <?count(G_1)?>, gives the count without looping

Related

prevent word counting of multiple spaces between words in textarea (html / javascript)

I have a textarea id="task", which has a word counter id="count" connected. The counter is set to count spaces between words, so a word is only accounted for if one puts a space after it. However, if for whatever reason one finds themself in a frenzy of hitting the spacebar, each and every space is then counted as a word which thwarts the final count. Below is the code for you to see for yourselves.
What I am asking is as follows:
1) Is there a way to count only one space after each word and ignore multiple spaces?
2) Can I prevent multiple spaces in the textarea?
Since I am suspecting that the solution dwells within the realm of javascript, I kindly ask for your help as I am still a noob. I will be grateful for any suggestions, be it 1) or 2).
HTML:
<div class="options">
Task:
<textarea type="text" rows="10" cols="97" name="task" id="task" onkeypress="onTestChange01();"
autocorrect="off" spellcheck="false"></textarea>
<p>Word count: <textarea cols="10" name="count" id="count" readonly>0</textarea></p>
</div>
JAVASCRIPT:
// WORD COUNTER FUNCTION
var count = document.getElementById('count');
var input = document.getElementById('task');
input.addEventListener('keyup', function(e){
wordCounter(e.target.value);
});
function wordCounter(text) {
var text = input.value;
var wordCount = 0;
for (var i = 0; i <= text.length; i++) {
if (text.charAt(i) == ' ') {
wordCount++;
}
}
count.innerText = wordCount;
}
I tried fiddling with the JS function and its values.
Also, I found a function to change multiple spaces to one space, which did not work as expected and it disrupted the original function and the counting.
Finally, I tried preventing 'space' altogether in the textarea properties but all in vain.
Looking forward to your ideas. Thanks.
tk

ColdFusion : String : Get Price From Inside 2 Points

I'm playing with the NOMICS API and get data in a string. But I'm having trouble getting just the Price:
This is part of the string from the METHOD=GET - which works fine..
"currency":"SHIB","platform_currency":"ETH","price":"0.000026199726","price_date":"2022-02-06T00:00:00Z","price_timestamp":"
I know that ,"price":" is the lead and then "," is the end...
But I can't seem to get just the 0.000026199726 from the middle- which is what I need.
<CFHTTP METHOD="Get"
URL="https://api.nomics.com/v1/currencies/ticker?key=#apikey#&ids=SHIB">
<cfset feedData = cfhttp.filecontent>
<cfset startpos = findNoCase(',"price":"', feedData)>
<cfset endpos = findNoCase('",', feedData)>
<cfset getdata = mid(feeddata,startpos,endpos-startpos)
<b>#getdata#</b> Errors as neg number.
The value of parameter 3 of the function Mid, which is now -191, must be a non-negative integer
This has to be an easy task. I must be using the wrong string function?
EDIT: Figured out - it was finding the "," but they are so many of them it found first one, which put things negative - so fix was to find the structure after. ","price_date" is after.
<cfset string = cfhttp.filecontent>
<cfset startpos = findNoCase('price":"', string)>
<cfset endpos = findNoCase('","price_date"', string)>
<cfset detdata = mid(string,startpos,endpos-startpos)>
<cfoutput>
start: #startpos#<br>
end: #endpos#<br>
data: #detdata#<br>
trimmed data: #trim(detdata)#<br>
trimmed data:
<br><b>#removechars(detdata,1,8)#</b><br><br>
</cfoutput>
I'll look at the JSON examples as well. Perhaps that will help with multiple pulls.
Excellent Folks : Thank you so much
<CFHTTP METHOD="Get"
URL="https://api.nomics.com/v1/currencies/ticker?key=#apikey#&ids=SHIB,BTC">
<cfset output = cfhttp.filecontent>
<cfoutput>
<cfset arrayOfStructs = deserializeJson(output)>
<cfloop array="#arrayOfStructs#" index="getpr">
<cfset Price = getpr.price />
<cfset TKID = getpr.id />
#tkid#: #price#<br>
</cfloop>
</cfoutput>
Spits out:
BTC: 43963.45841296
SHIB: 0.000033272664
Credit to Andrea/SOS
<CFHTTP METHOD="Get"
URL="https://api.nomics.com/v1/currencies/ticker?key=#apikey#&ids=SHIB,BTC">
<cfset output = cfhttp.filecontent>
<cfoutput>
<cfset arrayOfStructs = deserializeJson(output)>
<cfloop array="#arrayOfStructs#" index="getpr">
<cfset Price = getpr.price />
<cfset TKID = getpr.id />
#tkid#: #price#<br>
</cfloop>
</cfoutput>

Tag search in HTML using js in ant

I am using the below mentioned code to get the content of a specific tag, but when I am trying to execute it I am getting some extra data along with it, I don't understand why is it happening. Lets say if I search for title tag then I am getting " [echo] Title : <title>Unit Test Results</title>,Unit Test Results" this as result, but the problem is title only contains "<title>Unit Test Results</title>" why this extra ",Unit Test Results" thing is coming.
<project name="extractElement" default="test">
<!--Extract element from html file-->
<scriptdef name="findelement" language="javascript">
<attribute name="tag" />
<attribute name="file" />
<attribute name="property" />
<![CDATA[
var tag = attributes.get("tag");
var file = attributes.get("file");
var regex = "<" + tag + "[^>]*>(.*?)</" + tag + ">";
var patt = new RegExp(regex,"g");
project.setProperty(attributes.get("property"), patt.exec(file));
]]>
</scriptdef>
<!--Only available target...-->
<target name="test">
<loadfile srcFile="E:\backup\latest report\Report-20160523_2036.html" property="html.file"/>
<findelement tag="title" file="${html.file}" property="element"/>
<echo message="Title : ${element}"/>
</target>
The return value of RegExp.exec() is an array. From the Mozilla documentation on RegExp.prototype.exec():
The returned array has the matched text as the first item, and then
one item for each capturing parenthesis that matched containing the
text that was captured.
If you add the following code to your JavaScript...
var patt = new RegExp(regex,"g");
var execResult = patt.exec(file);
print("execResult: " + execResult);
print("execResult.length: " + execResult.length);
print("execResult[0]: " + execResult[0]);
print("execResult[1]: " + execResult[1]);
...you'll get the following output...
[findelement] execResult: <title>Unit Test Results</title>,Unit Test Results
[findelement] execResult.length: 2
[findelement] execResult[0]: <title>Unit Test Results</title>
[findelement] execResult[1]: Unit Test Results

Ant script looping iteration

I need to iterate two property in build.xml
<target name="sample">
<property name="modules" value="" />
<property name="env" value="" />
</target>
Can any one help me to write looping concept I need to iterate two property at same time. for example ( property " modules " having list of values like = " a, b ,c d )( property " env " having list of values like = x, y ,z . )
I need value to get = modules.env .. it will gives a.x or b.y in iteration loop. So can any one help how to loop at the same time?
You can always try javascript for non-trivial tasks
<project name="proj">
<property name="modules" value="a,b,c,d" />
<property name="env" value="x,y,z,w" />
<script language="javascript"> <![CDATA[
var modules = proj.getProperty("modules").split(",");
var env = proj.getProperty("env").split(",");
var size = Math.min(modules.length, env.length);
for(var i = 0; i < size; ++i) {
proj.setProperty("mp." + i, modules[i] + "." + env[i]);
}
]]></script>
<echo message="${mp.0}" />
<echo message="${mp.1}" />
<echo message="${mp.2}" />
<echo message="${mp.3}" />
</project>

new line for tooltip fetching values from the database

$price = mysql_result($result, $num, "drinks_shot"); $price2 = mysql_result($result, $num, "drinks_bottle");
$append = $clean_name.'<br> Per shot: Php'.$price.'<br> Per bottle: Php'.$price2.'.00'; $description = mysql_result($result, $num, "drinks_image"); echo "<td class='label'><img src='". mysql_result($result, $num, 'drinks_image')."' onclick='addtocart(". mysql_result($result, $num, 'drinks_id').")' class='masterTooltip' title= '".$append."'<br>";
if only i could make it display like
hennessy
price1
price2
i found similar posts regarding my problem but none of them are really working. Please help. :(
You want linebreaks inside a title="" tooltip? Instead of using <br>, use \n and make sure it's inside double (") quotes and not single quotes. Like so:
$append = $clean_name . "\n Per shot: Php" . $price . "\n ...";

Resources