Skip to content

Commit 70cc65b

Browse files
committed
add another version of transformXcos
1 parent 48aa895 commit 70cc65b

1 file changed

Lines changed: 27 additions & 15 deletions

File tree

blocks/eda-frontend/src/utils/GalleryUtils.js

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,7 @@ const splitBlock = /<SplitBlock /g
2424

2525
export const transformXcos = async (xmlDoc) => {
2626
const splitProcessor = await getSplitXsltProcessor()
27-
let dataDump = new XMLSerializer().serializeToString(xmlDoc)
28-
let count = dataDump.match(splitBlock).length
29-
console.log('count=', count)
30-
while (count > 0) {
31-
xmlDoc = splitProcessor.transformToDocument(xmlDoc)
32-
dataDump = new XMLSerializer().serializeToString(xmlDoc)
33-
const matches = dataDump.match(splitBlock)
34-
const newCount = matches ? matches.length : 0
35-
if (newCount !== count - 1) {
36-
console.error('newCount=', newCount, ', count=', count)
37-
throw new Error('count mismatch')
38-
}
39-
count = newCount
40-
console.log('count=', count)
41-
}
27+
xmlDoc = removeSplits1(xmlDoc, splitProcessor)
4228
const processor = await getXsltProcessor()
4329
xmlDoc = processor.transformToDocument(xmlDoc)
4430
return xmlDoc
@@ -60,6 +46,29 @@ const removeOneSplit = (xmlDoc, count, splitProcessor) => {
6046
return { xmlDoc, count: newCount }
6147
}
6248

49+
const removeSplits1 = (xmlDoc, splitProcessor) => {
50+
const removeNextSplit = (xmlDoc, count, splitProcessor) => {
51+
const rv = removeOneSplit(xmlDoc, count, splitProcessor)
52+
xmlDoc = rv.xmlDoc
53+
count = rv.count
54+
console.log('count=', count)
55+
if (count === 0) {
56+
return xmlDoc
57+
}
58+
59+
return removeNextSplit(xmlDoc, count, splitProcessor)
60+
}
61+
62+
const dataDump = new XMLSerializer().serializeToString(xmlDoc)
63+
const count = dataDump.match(splitBlock).length
64+
console.log('count=', count)
65+
if (count === 0) {
66+
return xmlDoc
67+
}
68+
69+
return removeNextSplit(xmlDoc, count, splitProcessor)
70+
}
71+
6372
const removeSplits = async (xmlDoc, splitProcessor, delay) => {
6473
const removeNextSplit = async (xmlDoc, count, splitProcessor) => {
6574
const rv = removeOneSplit(xmlDoc, count, splitProcessor)
@@ -81,6 +90,9 @@ const removeSplits = async (xmlDoc, splitProcessor, delay) => {
8190
const dataDump = new XMLSerializer().serializeToString(xmlDoc)
8291
const count = dataDump.match(splitBlock).length
8392
console.log('count=', count)
93+
if (count === 0) {
94+
return xmlDoc
95+
}
8496

8597
return new Promise((resolve) => {
8698
setTimeout(() => {

0 commit comments

Comments
 (0)