### Bug description

Cross references to section headings are wrong (rendered in-text as a reference to the last appendix with a `#sec id`) when:

- the project is of type book
- when rendering to docx only (pdf and html render correctly)
- the project is using an appendices key in the book config in the _quarto.yml
- there are `#sec ids` in the appendices 
- using cross-references to section headings (either chapters or appendices) 

Note that the text rendering of the cross reference in the body text is incorrect, but the hyperlink to the section in the document is correct. For example, the cross reference may appear in body text as "Appendix B", but it correctly links to "Chapter 1".

I have attached a zip archive of a book project as an example (created using `quarto create-project word_append_xref --type book`). Note that this cannot be reproduced using a single qmd file.
[word_append_xref.zip](https://github.com/quarto-dev/quarto-cli/files/9238654/word_append_xref.zip)


Source:

```
An xref to the Preface, @sec-one. This should read "Chapter 1".

An xref to the Intro (now Appendix A), @sec-two. This should read "Chapter A", as it
is in the appendices section of the YAML.

Another xref to the Intro (now Appendix A), [Appendix -@sec-two]. This should read "Appendix A",
as it refers to the appendix explicitly and uses the number-only form of cross reference.

An xref to the Summary (now Appendix B), @sec-three. This should read "Chapter B", as it
is in the appendices section of the YAML.

```

Output (created using `quarto render --to docx`):

![Screen Shot 2022-08-02 at 12 42 47 pm](https://user-images.githubusercontent.com/105196998/182280379-f3c0af01-ae54-4c92-9bc9-11ee662ea75f.png)

and with field codes toggled:

![Screen Shot 2022-08-02 at 12 43 19 pm](https://user-images.githubusercontent.com/105196998/182280437-cf4f306e-45c4-4c04-8e08-bd3f8f5b5a43.png)






### `quarto check` Output

```
[✓] Checking Quarto installation......OK
      Version: 1.0.37
      Path: /Applications/quarto/bin

[✓] Checking basic markdown render....OK

[✓] Checking Python 3 installation....OK
      Version: 3.9.13
      Path: /opt/homebrew/opt/python@3.9/bin/python3.9
      Jupyter: 4.10.0
      Kernels: python3

[✓] Checking Jupyter engine render....OK

[✓] Checking R installation...........OK
      Version: 4.2.1
      Path: /Library/Frameworks/R.framework/Resources
      LibPaths:
        - /Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library
      rmarkdown: 2.14.2

[✓] Checking Knitr engine render......OK
```

### `quarto tools check` Output

```
[✓] Inspecting tools

Tool         Status                    Installed     Latest  
chromium     Up to date                869685        869685  
tinytex      External Installation     ---           v2022.08
```

### Checklist

- [X] [formatted your issue](https://yihui.org/issue/#please-format-your-issue-correctly) so it is easier for us to read?
- [X] included a minimal, fully reproducible example in a single .qmd file? Please provide the whole file rather than the snippet you believe is causing the issue.
- [X] documented the quarto version you're running, by pasting the output from running `quarto check` in the "Quarto Check Output" text area?
- [X] documented the version of the quarto tools you're running, by providing the output from running `quarto tools check` in the "Quarto Tools Check Output" text area?
- [X] documented the RStudio IDE version you're running (if applicable), by providing the value displayed in the "About RStudio" main menu dialog?
- [X] documented which operating system you're running? If on Linux, please provide the specific distribution as well.
- [X] upgraded to the latest version, including your versions of R, the RStudio IDE, and relevant R packages?
jjallaire
2022-08-02T02:45:05Z
dan-cloney
bug
v1.1
closed
Cross references for section headings fail when there are appendices and the book is rendered in docx format.
https://github.com/quarto-dev/quarto-cli/issues/1637