Skip to content

Updated xpath part to remove all splitblocks #337

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: xcosblocks
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions blocks/eda-frontend/public/splitblock.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,7 @@
<!-- }}}1 -->

<!-- SplitBlock template {{{1 -->
<xsl:template match="/XcosDiagram/mxGraphModel/root/SplitBlock[position() = 1]">
<xsl:template match="//SplitBlock[position() = 1]">
<xsl:variable name="InputPort" select="key('k-explicitinput', @id)" />
<xsl:variable name="OutputPort" select="key('k-explicitoutput', @id)" />

Expand Down Expand Up @@ -1061,9 +1061,9 @@
<!-- Port template {{{1 -->
<xsl:template match="ExplicitInputPort | ExplicitOutputPort | ImplicitInputPort | ImplicitOutputPort | ControlPort | CommandPort">
<xsl:variable name="parentId" select="@parent" />
<xsl:variable name="SPLIT" select="/XcosDiagram/mxGraphModel/root/SplitBlock[position() = 1]" />
<xsl:variable name="SPLIT" select="(//SplitBlock)[1]/@id" />

<xsl:if test="$parentId != $SPLIT/@id">
<xsl:if test="$parentId != $SPLIT">
<xsl:copy>
<xsl:copy-of select="@*" />
<xsl:copy-of select="node()" />
Expand All @@ -1076,7 +1076,7 @@
<xsl:template match="ExplicitLink | CommandControlLink | ImplicitLink">
<xsl:variable name="sourceElement" select="key('k-portorlink', @source)" />
<xsl:variable name="targetElement" select="key('k-portorlink', @target)" />
<xsl:variable name="SPLITID" select="/XcosDiagram/mxGraphModel/root/SplitBlock[position() = 1]/@id" />
<xsl:variable name="SPLITID" select="(//SplitBlock)[1]/@id" />
<xsl:if test="$sourceElement/@parent != $SPLITID and $targetElement/@parent != $SPLITID">
<xsl:variable name="srcsrcid" select="key('k-portorlink', $sourceElement/@source)/@parent" />
<xsl:variable name="srctgtid" select="key('k-portorlink', $sourceElement/@target)/@parent" />
Expand Down
4 changes: 2 additions & 2 deletions blocks/eda-frontend/src/utils/GalleryUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const getSplitXsltProcessor = async () => {
return processor
}

const splitBlockXPathCount = 'count(/XcosDiagram/mxGraphModel/root/SplitBlock)'
const splitBlockXPathCount = 'count(//SplitBlock)'

const countNodesByXPath = (xpath, contextNode) => {
const result = contextNode.evaluate(xpath, contextNode, null, XPathResult.NUMBER_TYPE, null)
Expand Down Expand Up @@ -62,7 +62,7 @@ const removeOneSplit = (xmlDoc, count, splitProcessor) => {

xmlDoc = splitProcessor.transformToDocument(xmlDoc)
const newCount = countNodesByXPath(splitBlockXPathCount, xmlDoc)
if (newCount !== count - 1) {
if (newCount >= count) {
console.error('newCount=', newCount, ', count=', count)
throw new Error('count mismatch')
}
Expand Down
21 changes: 15 additions & 6 deletions blocks/xcos2xml/replacesplitblocks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ if test -n "$INPUTXML"; then
Xcos/MxGraphParser.py "$INPUTXML" "$WORKSPACE" "$CONTEXT"
fi

count=$(grep -c '^ <SplitBlock' "$INPUT") || :
# count=$(grep -c '^ <SplitBlock' "$INPUT") || :
count=$(grep -c '^[[:space:]]*<SplitBlock' "$INPUT") || :
INPUT1="$BASE-$count.xml"
echo "Creating $INPUT1"
cp -f "$INPUT" "$INPUT1"
Expand All @@ -102,15 +103,23 @@ while test $count -gt 0; do

xsltproc "$SPLITXSL" "$INPUT1" >"$TMPFILE1"
xmllint --format "$TMPFILE1" >"$TMPFILE2"
count=$(grep -c '^ <SplitBlock' "$TMPFILE2") || :
# count=$(grep -c '^ <SplitBlock' "$TMPFILE2") || :
count=$(grep -c '^[[:space:]]*<SplitBlock' "$TMPFILE2") || :

if ((count >= oldcount)); then
echo "ERROR: SplitBlock count did not decrease (old=$oldcount, new=$count)" >&2
exit 2
fi
INPUT1="$BASE-$count.xml"
echo "Creating $INPUT1"
cp -f "$TMPFILE2" "$INPUT1"

if ((count != oldcount - 1)); then
echo "ERROR: $count != $oldcount - 1" >&2
exit 2
fi
# if ((count != oldcount - 1)); then
# if ((count < oldcount)); then
# # echo "ERROR: $count != $oldcount - 1" >&2
# echo "ERROR: $count < $oldcount" >&2
# exit 2
# fi
done

xsltproc "$XSL" "$INPUT1" >"$TMPFILE1"
Expand Down