问题
1)
I was thinking purpose of he AbstractNum
is to reuse the numbering format and NumberingInstance
is to create new list (restart at 1). But what I've noticed is if restart the second instance of the list at 1, openxml document will have a exact copy of the AbstractNum
element (only difference is Nsid
) and a NumberingInstance
pointing to that AbstractNum
element.
ex: If I have a list as follows
- Item 1
- Item 2
and another list as below with exact same styling but restart at 1
- Item 3
- Item 4
This will produce two copies of AbstractNum
(with same definition) and two copies of NumberingInstance
. What is the purpose of having duplicate definition (AbstractNum
) if the styling is the same
2)
If need to create duplicate AbstractNum
for each NumberingInstance
, can someone tell me how to generate the Nsid
value (hex). it looks like if you have two AbstractNum
with same Nsid
will also causing the continuation of list numbering (instead of start at 1 for the second list) But I don't know how to generate a unique Nsid
回答1:
Regarding the first part of your question, it is important to understand that you can sometimes use different Open XML markup to achieve the same effect. Just because Microsoft Word produces markup in a certain way does not mean your way is incorrect, as long as your way is compliant with the standard.
Enhancing my original answer, here's an example of how you would restart numbering without duplicating the w:abstractNum
element, using roughly the text provided in the question:
Unnumbered text before first list.
1. Item 1
2. Item 2
Unnumbered text before second list.
1. Item 3 (restarted)
2. Item 4
Let's look at the corresponding main document part (document.xml
), noting that I've simplified the markup created by Microsoft Word:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<w:document xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
<w:body>
<w:p>
<w:r>
<w:t>Unnumbered text before first list.</w:t>
</w:r>
</w:p>
<w:p>
<w:pPr>
<w:pStyle w:val="ListParagraph"/>
<w:numPr>
<w:ilvl w:val="0"/>
<w:numId w:val="1"/>
</w:numPr>
</w:pPr>
<w:r>
<w:t>Item 1</w:t>
</w:r>
</w:p>
<w:p>
<w:pPr>
<w:pStyle w:val="ListParagraph"/>
<w:numPr>
<w:ilvl w:val="0"/>
<w:numId w:val="1"/>
</w:numPr>
</w:pPr>
<w:r>
<w:t>Item 2</w:t>
</w:r>
</w:p>
<w:p>
<w:r>
<w:t>Unnumbered text before second list.</w:t>
</w:r>
</w:p>
<w:p>
<w:pPr>
<w:pStyle w:val="ListParagraph"/>
<w:numPr>
<w:ilvl w:val="0"/>
<w:numId w:val="2"/>
</w:numPr>
</w:pPr>
<w:r>
<w:t>Item 3 (restarted)</w:t>
</w:r>
</w:p>
<w:p>
<w:pPr>
<w:pStyle w:val="ListParagraph"/>
<w:numPr>
<w:ilvl w:val="0"/>
<w:numId w:val="2"/>
</w:numPr>
</w:pPr>
<w:r>
<w:t>Item 4</w:t>
</w:r>
</w:p>
</w:body>
</w:document>
You will note that the two lists are referencing two numbering ids (1 and 2) in their w:numId
elements.
Next, here is the corresponding numbering definitions part (numbering.xml
):
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<w:numbering xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"
xmlns:w15="http://schemas.microsoft.com/office/word/2012/wordml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="w15">
<!-- This is the only w:abstractNum element in numbering.xml -->
<w:abstractNum w:abstractNumId="0" w15:restartNumberingAfterBreak="0">
<w:nsid w:val="23B5103A"/>
<w:multiLevelType w:val="hybridMultilevel"/>
<w:tmpl w:val="40963B22"/>
<!-- The following w:lvl is referenced by w:ilvl with w:val="0" -->
<w:lvl w:ilvl="0" w:tplc="0409000F">
<w:start w:val="1"/>
<w:numFmt w:val="decimal"/>
<w:lvlText w:val="%1."/>
<w:lvlJc w:val="left"/>
<w:pPr>
<w:ind w:left="720" w:hanging="360"/>
</w:pPr>
</w:lvl>
<!-- Markup for numbering levels 1-7 removed -->
<w:lvl w:ilvl="8" w:tplc="0409001B" w:tentative="1">
<!-- Child elements removed -->
</w:lvl>
</w:abstractNum>
<!-- The following w:num is referenced by the w:numId with w:val="1" -->
<w:num w:numId="1">
<w:abstractNumId w:val="0"/>
</w:num>
<!-- The following w:num is referenced by the w:numId with w:val="2" -->
<w:num w:numId="2">
<w:abstractNumId w:val="0"/>
<!-- The w:lvlOverride with its w:startOverride child restarts numbering -->
<w:lvlOverride w:ilvl="0">
<w:startOverride w:val="1"/>
</w:lvlOverride>
<!-- You can also override levels 1 to 8 in the same way, if required -->
</w:num>
</w:numbering>
You can see that this uses only one w:abstractNum
that is referenced by two `w:num' elements, one of which overrides the at least one level by restarting the numbering.
Regarding the second part of your question, if you want to mimic the behavior of Microsoft Word, the value of the w:nsid
element (Abstract Numbering Definition Identifier) is simply a unique number stated as a long hex number. The standard is silent about how exactly it should be created. So, for example, you can take pretty much any number that is not yet used by any w:abstractNum
element.
来源:https://stackoverflow.com/questions/58622437/purpose-of-abstractnum-and-numberinginstance