I am not a programmer and need some help from the pros. If I have more than one validation I want to check for exampel I want this result when test = 78 or 81 otherwise.
I have tried using without succcess
<xsl:variable name = "vatTerm">
<xsl:choose>
<xsl:when test="(DocumentXML/ApplicationObject/Object/CarTypeId!='78') and (CarTypeId!='81')">
<xsl:value-of select="(($netterm+$termfee)*$vatrate )+$eptermfeetotalvat"/>
</xsl:when>
<xsl:otherwise><xsl:value-of select ="$eptermfeetotalvat"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
Also tried;
<xsl:choose>
<xsl:when test="(DocumentXML/ApplicationObject/Object/CarTypeId!=78">
<xsl:value-of select="(($netterm+$termfee)*$vatrate )+$eptermfeetotalvat"/>
</xsl:when>
<xsl:when test="(DocumentXML/ApplicationObject/Object/CarTypeId!=81">
<xsl:value-of select="(($netterm+$termfee)*$vatrate )+$eptermfeetotalvat"/>
</xsl:when>
<xsl:otherwise><xsl:value-of select ="$eptermfeetotalvat"/></xsl:otherwise>
</xsl:choose>
You got the DeMorgan right.
But you forgot that the path's base is not duplicated. So, I guess, you should try
<xsl:when test="DocumentXML/ApplicationObject/Object/CarTypeId!='78' and DocumentXML/ApplicationObject/Object/CarTypeId!='81'">
<xsl:value-of select="(($netterm+$termfee)*$vatrate )+$eptermfeetotalvat"/>
</xsl:when>
This approach has the restriction that it checks if any CarTypeId at the given path is unequal to 78 or 81. If you have only one CarTypeId, this will be working fine with XPath-1.0.
With XPath-2.0 you could simplify and precise this task.
I would use the one predicate like this
<xsl:choose>
<xsl:when test="DocumentXML/ApplicationObject/Object/CarTypeId[.!='78' and .!='81']">
<xsl:value-of select="(($netterm+$termfee)*$vatrate )+$eptermfeetotalvat"/>
</xsl:when>
<xsl:otherwise><xsl:value-of select ="$eptermfeetotalvat"/>
</xsl:otherwise>
</xsl:choose>
Related
Here's my code to select bullet types for different nested lists, but only the disc shows up in the PDF. How can I get a hollow circle and solid square symbol to show up?
<xsl:choose>
<xsl:when test="parent::ul[ancestor::ul[ancestor::ul]]"><!--double nested bullet-->
<xsl:attribute name="font-family">Times New Roman</xsl:attribute>
<fo:character character="■"/><!--solid square-->
</xsl:when>
<xsl:when test="parent::ul[ancestor::ul]"><!--single nested bullet-->
<xsl:attribute name="font-family">Times New Roman</xsl:attribute>
<fo:character character="∘"/><!--hollow circle-->
</xsl:when>
<xsl:otherwise><!--bullet-->
<xsl:attribute name="font-family">Times New Roman</xsl:attribute>
<fo:character character="•"/><!--disc-->
</xsl:otherwise>
</xsl:choose>
I couldn't figure this out, so I just created png files for the glyphs, which is probably what I should have done in the first place. In case it's helpful to anyone else, here are the images I used:
Here's a screenshot of the output:
And here's the new code:
<xsl:choose>
<xsl:when test="parent::ol">
<xsl:number format="1."/>
</xsl:when>
<xsl:when test="parent::ul[ancestor::ul[ancestor::ul]]"><!--double nested bullet-->
<fo:external-graphic src="{$staticImages}bullet-level-3.png"/>
</xsl:when>
<xsl:when test="parent::ul[ancestor::ul]"><!--single nested bullet-->
<fo:external-graphic src="{$staticImages}bullet-level-2.png"/>
</xsl:when>
<xsl:otherwise><!--bullet-->
<fo:external-graphic src="{$staticImages}bullet-level-1.png"/>
</xsl:otherwise>
</xsl:choose>
i need to add an attribute initial-page-number to a tag fo:sequence
tha tag is
<fo:page-sequence master-reference="alternating" initial-page-number="1"><fo:page-sequence>
..
...
</fo:page-sequence>
become
<fo:page-sequence master-reference="alternating" initial-page-number="1">
..
</fo:page-sequence>
but with the xslt i obtain two fo:page:
<fo:page-sequence master-reference="alternating" initial-page-number="1"><fo:page-sequence>
</fo:page-sequence></fo:page-sequence>
How can i replace old fo:page-sequence with new one?
This is my xsl stylesheet:
<xsl:stylesheet>
<xsl:template match="ss:split/fo:page-sequence">
<xsl:choose>
<xsl:when test="#master-reference['alternating']">
<xsl:element name="fo:page-sequence">
<xsl:for-each select="#*">
<xsl:attribute name="{name()}"><xsl:value-of select="."/></xsl:attribute>
</xsl:for-each>
<xsl:attribute name="initial-page-number">
<xsl:value-of select="1"/>
</xsl:attribute>
<xsl:copy>
<xsl:apply-templates select="child::*"/>
</xsl:copy>
</xsl:element>
</xsl:when>
</xsl:choose>
</xsl:template>
<xsl:template match='comment()'>
<xsl:comment><xsl:value-of select="."/></xsl:comment>
</xsl:template>
<xsl:template match="#*|*">
<xsl:copy>
<xsl:apply-templates select="#*|node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
Your stylesheet changes every fo:page-sequence because the predicate ['alternating'] is always true.
You can check for the master-reference value in the match pattern, plus you can just copy the existing attributes, and you can copy the contents of the fo:page-sequence since it won't contain another fo:page-sequence:
<xsl:template
match="ss:split/fo:page-sequence[#master-reference = 'alternating']">
<xsl:copy>
<xsl:copy-of select="#*" />
<xsl:attribute name="initial-page-number">1</xsl:attribute>
<xsl:copy-of select="node()" />
</xsl:copy>
</xsl:template>
Your stylesheet creates an fo:page-sequence using <xsl:element name="fo:page-sequence">, and another one with <xsl:copy> (as the matching element is an fo:page-sequence).
Just remove the xsl:copy (but leave <xsl:apply-templates select="child::*"/>, as you want to process the children of the current node!) and you should get what you need.
<xsl:variable name="targetReceiverService">
<EMP_EMPLOC_MAL curr="4.0">MAL</EMP_EMPLOC_MAL>
<EMP_EMPLOC_SIN curr="1.6">SIN</EMP_EMPLOC_SIN>
<EMP_EMPLOC_CHN curr="7.8">CHN</EMP_EMPLOC_CHN>
<DEFAULT curr="1.0">NONE</DEFAULT>
</xsl:variable>
<xsl:variable name="targetCountryCode" select="$targetReceiverService/*[name() = $ReceiverService] | $targetReceiverService/DEFAULT"/>
<xsl:value-of select="$targetCountryCode "/>
why value display for $targetCountryCode is only MAL but not included NONE since the "|" mean
xsl:value-of only displays the value of the first node in the set. (at least with XSL 1)
You can probably display all of them with
<xsl:for-each select="$targetCountryCode">
<xsl:value-of select="."/>
</xsl:for-each>
I am using selenium with perl and have label on page, to access this label i have following xpath: //*[text()='some here'] , the problem that a need to get full xpath of this element, like /html/body/table/tr/..../any other/and other/ , is there is any selenium method or perl function ? looking for perl solution or any other working things.
thanks
looking for perl solution or any other
working things
This XPath 2.0 expression:
string-join(for $node in ancestor-or-self::node()
return concat(('#')[$node/self::attribute()],
$node/name(),
(concat('[',
count($node/preceding-sibling::node()
[name()=$node/name()]) + 1,
']'))[$node/../node()
[name()=$node/name()][2]]),
'/')
Edit: Shorter expression.
This XSLT 1.0 transformation produces an XPath expression for every node contained in the $pNode parameter:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="node()|#*">
<path>
<xsl:call-template name="buildPath"/>
</path>
<xsl:apply-templates select="node()|#*"/>
</xsl:template>
<xsl:template name="buildPath">
<xsl:variable name="pNode" select="."/>
<xsl:variable name="theResult">
<xsl:for-each select="$pNode">
<xsl:variable name="theNode" select="."/>
<xsl:for-each select=
"$theNode
|
$theNode/ancestor-or-self::node()[..]">
<xsl:element name="slash">/</xsl:element>
<xsl:choose>
<xsl:when test="self::*">
<xsl:element name="nodeName">
<xsl:value-of select="name()"/>
<xsl:variable name="thisPosition" select=
"count(preceding-sibling::*
[name(current())
=
name()])"/>
<xsl:variable name="numFollowing" select=
"count(following-sibling::
*[name(current())
=
name()])"/>
<xsl:if test="$thisPosition + $numFollowing > 0">
<xsl:value-of select=
"concat('[', $thisPosition +1, ']')"/>
</xsl:if>
</xsl:element>
</xsl:when>
<xsl:otherwise> <!-- This node is not an element -->
<xsl:choose>
<xsl:when test="count(. | ../#*) = count(../#*)">
<!-- Attribute -->
<xsl:element name="nodeName">
<xsl:value-of select="concat('#',name())"/>
</xsl:element>
</xsl:when>
<xsl:when test="self::text()"> <!-- Text -->
<xsl:element name="nodeName">
<xsl:value-of select="'text()'"/>
<xsl:variable name="thisPosition"
select="count(preceding-sibling::text())"/>
<xsl:variable name="numFollowing"
select="count(following-sibling::text())"/>
<xsl:if test="$thisPosition + $numFollowing > 0">
<xsl:value-of select=
"concat('[', $thisPosition +1, ']')"/>
</xsl:if>
</xsl:element>
</xsl:when>
<xsl:when test="self::processing-instruction()">
<!-- Processing Instruction -->
<xsl:element name="nodeName">
<xsl:value-of select="'processing-instruction()'"/>
<xsl:variable name="thisPosition"
select="count(preceding-sibling::processing-instruction())"/>
<xsl:variable name="numFollowing"
select="count(following-sibling::processing-instruction())"/>
<xsl:if test="$thisPosition + $numFollowing > 0">
<xsl:value-of select=
"concat('[', $thisPosition +1, ']')"/>
</xsl:if>
</xsl:element>
</xsl:when>
<xsl:when test="self::comment()"> <!-- Comment -->
<xsl:element name="nodeName">
<xsl:value-of select="'comment()'"/>
<xsl:variable name="thisPosition"
select="count(preceding-sibling::comment())"/>
<xsl:variable name="numFollowing"
select="count(following-sibling::comment())"/>
<xsl:if test="$thisPosition + $numFollowing > 0">
<xsl:value-of select=
"concat('[', $thisPosition +1, ']')"/>
</xsl:if>
</xsl:element>
</xsl:when>
<!-- Namespace: -->
<xsl:when test=
"count(. | ../namespace::*)
=
count(../namespace::*)">
<xsl:variable name="apos">'</xsl:variable>
<xsl:element name="nodeName">
<xsl:value-of select="concat('namespace::*',
'[local-name() = ', $apos, local-name(), $apos, ']')"/>
</xsl:element>
</xsl:when>
</xsl:choose>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
<!-- <xsl:text>
</xsl:text> -->
</xsl:for-each>
</xsl:variable>
<xsl:value-of select="$theResult"/>
</xsl:template>
</xsl:stylesheet>
when applied on the following XML document:
<div id="entry-1" class="item-asset asset hentry">
<div class="asset-header">
<h2 class="asset-name entry-title">
<a rel="bookmark" href="http://blahblah.com/paper-scissors">Paper Scissors</a>
</h2>
</div>
<div class="asset-content entry-content">
<div class="asset-body">
<p>Paper and scissors</p>
</div>
</div>
</div>
the result is a list of the XPath expressions for every node in the document:
<path>/div</path>
<path>/div/#id</path>
<path>/div/#class</path>
<path>/div/div[1]</path>
<path>/div/div[1]/#class</path>
<path>/div/div[1]/h2</path>
<path>/div/div[1]/h2/#class</path>
<path>/div/div[1]/h2/a</path>
<path>/div/div[1]/h2/a/#rel</path>
<path>/div/div[1]/h2/a/#href</path>
<path>/div/div[1]/h2/a/text()</path>
<path>/div/div[2]</path>
<path>/div/div[2]/#class</path>
<path>/div/div[2]/div</path>
<path>/div/div[2]/div/#class</path>
<path>/div/div[2]/div/p</path>
<path>/div/div[2]/div/p/text()</path>
I have this function which tries to replace dots and/or - with _
I'm limited to use xpath 1 so replace function is NOT an option. The template works not to much fine because if I use something like this:
FOO-BAR.THING-MADRID.html
it gives me out on screen this thing:
FOO-BAR.THING-MADRID.html
the middle dot is not replaced.
Someone could help me?
<xsl:template name="replaceDots">
<xsl:param name="outputString"/>
<xsl:variable name="target">.</xsl:variable>
<xsl:variable name="source">-</xsl:variable>
<xsl:variable name="replacement">_</xsl:variable>
<xsl:choose>
<xsl:when test="contains($outputString,$source)">
<xsl:value-of select="concat(substring-before($outputString,$source),$replacement)" disable-output-escaping="yes"/>
<xsl:call-template name="replaceDots">
<xsl:with-param name="outputString" select="substring-after($outputString,$source)"/>
</xsl:call-template>
</xsl:when>
<xsl:when test="contains($outputString,$target)">
<xsl:value-of select="concat(substring-before($outputString,$target),$replacement)" disable-output-escaping="yes"/>
<xsl:call-template name="replaceDots">
<xsl:with-param name="outputString" select="substring-after($outputString,$target)"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$outputString" disable-output-escaping="yes"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
To replace all dots or dashes with underscores, you do not need an <xsl:template>. You can use:
<xsl:value-of select="translate(., '-.', '__')" />
If you want to keep the ".html", you can extend this like so:
<xsl:value-of select="
concat(
translate(substring-before(., '.html'), '-.', '__'),
'.hmtl'
)
" />
For a generic "string replace" template in XSLT, look at this question, for example.